wpf 相关问题

Windows Presentation Foundation或WPF是用于在基于Windows的应用程序中呈现用户界面的子系统。

如何让屏幕阅读器以类似于读取 Win32 MessageBox 的方式读取我的 WPF 消息?

我们有一个 WPF 桌面应用程序,需要显示一些自定义消息窗口。我无法让屏幕阅读器(例如 Freedom Scientific 的 JAWS)正确朗读它们......

回答 6 投票 0

CurrentViewModel 属性更改未反映在 ContentControl 中

我目前正在构建一个应用程序,用户可以通过一组单选按钮选择不同的页面。当页面处于活动状态时,我希望单选按钮被检查为 true。当b...

回答 2 投票 0

WPF 装饰器变换

我正在构建一个控件,用户可以在其中“绘制”覆盖在内容上的可调整大小的矩形。为了调整这些矩形的大小,我在它们上面使用了一个 Adorner,其中包含 4 个可以更改的 Thumbs...

回答 2 投票 0

WPF 中使用转换器的问题

我的数据库中有一个与序列化字节数组相对应的字符串。我希望能够修改该字符串中存在的字节并添加或删除其中的一些字节。 我正在转换我的字符串检索...

回答 1 投票 0

有没有办法影响WPF中半透明颜色之间的插值?

正如这个问题中所讨论的,我希望以下代码会产生两个相同的渐变: 正如这个问题中所讨论的那样,我希望以下代码会产生两个相同的looking渐变: <Border Background="Black"> <StackPanel> <Border x:Name="withOpacity" Height="32"> <Border.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="0" Color="#ff222222" /> <GradientStop Offset="1" Color="#33ff8000" /> </LinearGradientBrush> </Border.Background> </Border> <Border x:Name="withoutOpacity" Height="32"> <Border.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="0" Color="#ff222222" /> <GradientStop Offset="1" Color="#ff331a00" /> </LinearGradientBrush> </Border.Background> </Border> </StackPanel> </Border> 两个渐变的 visible 开始和结束颜色是相同的(在第二个渐变中,最终颜色是通过在给定的 #33 不透明度(即 20%)下将第一个渐变的结束颜色与黑色背景混合来计算的) )。不幸的是,插值非常不同: 上面链接的问题的公认答案解释了为什么会出现这种情况。我想知道是否有人能想到一种(编程)方法来在给定第一个梯度的输入值的情况下复制第二个梯度的插值。另外,我正在寻找渐变和彩色动画的解决方案。 我之前问题的回答者建议我可能只需要调整 alpha 分量的插值并且可以保留纯色值,但如果是这样的话,我还没有找到正确的算法......(由于最初的用例是动画,我在不透明度上尝试了各种缓动功能)经过一些实验,我也不再确定将不透明度与强度等同起来是否完全正确,就像该解释中的情况一样...... 请注意,我并不是(必然)寻找现成的解决方案,而是寻找有关如何解决最可能有价值的问题的建议。例如。创建 ColorAnimation 和 *GradientBrush 的自定义实现 vs 添加更明确的 GradientStops/关键帧 vs ...我还没想到的东西? 我探索这一点的原因是,我非常喜欢使用半透明颜色而不是预混合颜色,因为它将使渐变和动画独立于它们显示的背景(理想情况下,还包括非固体)彩色背景)。 由于您知道渐变透明度的百分比,因此您可以计算黑色百分比并导出第二种颜色。您可以将此计算交给值转换器来为您完成工作。您可能需要调整此计算以获得您想要的结果,但它应该会让您走上正确的道路。 以下是值转换器的样子: public class GradientNormalizer : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is Color color)) return value; var opacity = color.ScA; var r = color.ScR; var g = color.ScG; var b = color.ScB; var normalizedColor = new Color { ScA = 1, // since color is interpreted as approximately square ScR = r * opacity * opacity, ScG = g * opacity * opacity, ScB = b * opacity * opacity, }; return normalizedColor; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 这是您在 xaml 中使用它的方式 <Border x:Name="withOpacity" Height="32"> <Border.Resources> <local:GradientNormalizer x:Key="Normalizer" /> </Border.Resources> <Border.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="0" Color="{Binding StartColor, Converter={StaticResource Normalizer}}" /> <GradientStop Offset="1" Color="{Binding EndColor, Converter={StaticResource Normalizer}}" /> </LinearGradientBrush> </Border.Background> </Border> 本例中的数据模型: public Color StartColor => (Color)ColorConverter.ConvertFromString("#ff222222"); public Color EndColor => (Color)ColorConverter.ConvertFromString("#33ff8000");

回答 1 投票 0

Wpf 文本框光标悬停在鼠标上

我的应用程序中有一个窗口,这是一个小窗口,但 80% 是文本框。 我遇到的烦恼是,当我将鼠标悬停在文本框上时,光标保持为箭头,而我想要...

回答 1 投票 0

RelayCommand 未在 DataGridTextColumn WPF MVVM 内单击 MenuItem 时触发

我想在右键单击 EmpName 列上的“插入”菜单时添加新行,但它不会触发 InsertCommand。我在这里附上了 xaml 代码。请告诉我我在这里缺少什么。 我想在右键单击 EmpName 列上的“插入”菜单时添加新行,但它不会触发 InsertCommand。我在这里附上了 xaml 代码。请告诉我我在这里缺少什么。 <Window x:Class="DataGridRowsManagement.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:data="clr-namespace:DataGridRowsManagement" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <data:ViewModel x:Key="EmpVM"></data:ViewModel> </Window.Resources> <Grid DataContext="{Binding Source={StaticResource EmpVM}}"> <DataGrid AutoGenerateColumns="False" Height="287" HorizontalAlignment="Left" Margin="23,12,0,0" Name="dgEmp" VerticalAlignment="Top" Width="657" ItemsSource="{Binding Path=Employees}" ColumnWidth="*" SelectedIndex="{Binding Path=RecordIndex,Mode=TwoWay}"> <DataGrid.Columns> <DataGridTextColumn Header="EmpNo" Binding="{Binding EmpNo}" /> <DataGridTemplateColumn Header="EmpName"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding EmpName}" HorizontalAlignment="Stretch"> <TextBlock.ContextMenu> <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"> <MenuItem Command="{Binding InsertCommand}" CommandParameter="{Binding RecordIndex}" Header="Insert"/> <MenuItem Command="{Binding DeleteCommand}" CommandParameter="{Binding RecordIndex}" Header="Delete"/> </ContextMenu> </TextBlock.ContextMenu> </TextBlock> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="Salary" Binding="{Binding Salary}" /> <DataGridTextColumn Header="Designation" Binding="{Binding Designation}" /> </DataGrid.Columns> </DataGrid> </Grid> </Window> 这些绑定位于 DataTemplate 内,因此它们将尝试绑定到要模板化的项目。 尝试下一个: <Window ... x:Name="ThisWindow" <MenuItem Command="{Binding DataContext.InsertCommand, ElementName=ThisWindow}" />

回答 1 投票 0

WPF 身份验证,无需在代码中存储机密或证书信息

我有一个 WPF 应用程序,可以从 Azure 保管库收集机密。我已在 Azure 中创建了一个可以访问我的保管库的应用程序注册。为了获得保险库令牌,我需要存储应用程序注册表

回答 1 投票 0

为什么我的 Liveshare 合作伙伴看不到 Visual Studio 2022 上的 XAML 设计器?

如果我们尝试编写 WPF 应用程序并邀请我的朋友参加 LiveShare 会话,他只能看到 XAML 代码,而看不到设计器。其他一切都很好。 LiveShare 的其他一切都是...

回答 1 投票 0

为什么我的 Liveshare 合作伙伴看不到 Visual Studio 2022 上的 XAML 设计器?

如果我们尝试编写 WPF 应用程序并邀请我的朋友参加 LiveShare 会话,他只能看到 XAML 代码,而看不到设计器。其他一切都很好。 LiveShare 的其他一切都是...

回答 1 投票 0

如何使用 EF 存储/映射复杂数据类型?

CategoryModel 具有对象画笔类型(复杂数据类型)的属性和依赖属性颜色,无法直接使用 EF 存储,因此我使用序列化并将其存储为字符串。 使用系统...

回答 1 投票 0

使用 WPF 进行全局事件监控

我想在这件事上寻求帮助:在WPF中,我想监视keydown、mousedown和mousewheel事件,即使窗口当前不是活动的。我在WPF中使用c#。我尝试了很多...

回答 1 投票 0

WPF C# - 文本块输入未保存到导航到新页面?

我目前在 WPF 中的页面导航方面遇到问题,我目前有一个带有侧边栏的主窗口,以及窗口中间的一个框架来显示新页面。侧边栏导航似乎...

回答 1 投票 0

C# WPF 菜单在升级为 SDK 风格后不再起作用

问题:使用升级助手升级为SDK样式后,菜单不再起作用 初始点: 项目类型:WPF应用程序(.Net Framework) 默认生成App.xaml 修改MainWindow.xaml...

回答 1 投票 0

当我使用用户控件时,用户控件中的 WPF 图像未显示在编辑器中

在我的程序中,我有选项卡和选项卡栏用户控件来按住按钮以在它们之间切换。选项卡栏中的按钮是我制作的 TabButton 用户控件,其背面有图像...

回答 1 投票 0

将多个类绑定到 WPF 树视图

我的 Treeview 已正确绑定到 ClassModel,但我将有一些具有子 CADModel 的类模型,我无法让我的层次模板正常工作 提前致谢 马克 <

回答 1 投票 0

不支持BitmapEncoder保存

我有以下代码,我看不出有什么问题,有什么想法可能是什么问题吗? 私有静态字符串 SaveBaseImage( ZipArchive arc, DBImage image, int imageIndex ) { 使用 (...

回答 1 投票 0

如果无法通过样式设置子控件属性,如何通过 XAML 设置子控件属性

我想在用户控件中设置子控件的属性。 我想在用户控件中设置子控件的属性。 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="auto"/> </Grid.ColumnDefinitions> <Label Grid.Column="0" x:Name="cLabel" Content="{Binding Caption}" /> <TextBox Grid.Column="1" x:Name="cTextBox" Text="{Binding Text}"/> <Label Grid.Column="2" x:Name="cUnit" Content="{Binding Unit}"/> </Grid> <!-- how to set only cLabel Width? something like: --> <local:LabeledTextbox cLabel.Width=100> 我想它不可能通过样式,因为样式也会设置cUnit。对吗? 我尝试了样式,但它设置了所有子项。 您可以使用该元素的资源来设置这些属性。 <local:LabeledTextbox> <local:LabeledTextbox.Resources> <Style TargetType="Label"> <Setter Property="Width" Value="100" /> <Setter Property="BorderBrush" Value="Gray" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Margin" Value="4" /> <Setter Property="Foreground" Value="Purple" /> <Setter Property="FontStyle" Value="Italic" /> </Style> </local:LabeledTextbox.Resources> </local:LabeledTextbox> 或者,如果您想为多个控件设置该值,您可以将要隔离的内容块包装在某种容器控件中,并为包含元素设置资源,如下所示: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="auto" /> </Grid.ColumnDefinitions> <Label Grid.Column="0" x:Name="cLabel" Content="Caption" /> <TextBox Grid.Column="1" x:Name="cTextBox" Text="Text" /> <Label Grid.Column="2" x:Name="cUnit" Content="Unit" /> </Grid> <StackPanel> <StackPanel.Resources> <Style TargetType="Label"> <Setter Property="Width" Value="100" /> <Setter Property="BorderBrush" Value="Gray" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Margin" Value="4" /> <Setter Property="Foreground" Value="Purple" /> <Setter Property="FontStyle" Value="Italic" /> </Style> </StackPanel.Resources> <local:LabeledTextbox /> <local:LabeledTextbox /> <local:LabeledTextbox /> </StackPanel>

回答 1 投票 0

WPF 文件信息表

我对 C# 和 WPF 比较陌生,我是否在努力获取要显示的文件信息列表。下面是我正在使用的代码。我已经测试过该集合填充了正确的

回答 1 投票 0

如何在 WPF 中将动画设置为半透明颜色?

简化(!)示例: 简化(!)示例: <Window Background="Black"> <Button Background="#ff272727" Content="Whatever" Foreground="White" Padding="16,8" HorizontalAlignment="Center" VerticalAlignment="Center"> <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="container" Background="{TemplateBinding Background}"> <ContentPresenter Margin="{TemplateBinding Padding}" /> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0:0:2" /> </VisualStateGroup.Transitions> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> <Storyboard> <ColorAnimation Storyboard.TargetName="container" Storyboard.TargetProperty="Background.Color" To="#33ff8000" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Border> </ControlTemplate> </Button.Template> </Button> </Window> 将鼠标悬停在按钮上时,我希望颜色在 2 秒的时间内从 #ff272727(不透明深灰色)过渡到 #33ff8000(半透明橙色)。然而,实际发生的情况是,它首先非常快速地(我估计大约四分之一秒)过渡到看起来像 #ffff8000 的样子,然后在剩下的 2 秒内继续 #33ff8000 。 从本质上讲,它似乎是一个接一个地对颜色和 alpha 分量进行动画处理,而不是同时对两者进行动画处理。 有趣的是,如果我交换两种颜色的 alpha 值,即当我从半透明颜色设置动画为完全不透明颜色时,不会发生同样的事情。似乎只有当To颜色不透明时才会发生。 对我来说另一个有趣的观察是,即使使用这个故事板也会发生完全相同的现象: <Storyboard> <DoubleAnimation Storyboard.TargetName="container" Storyboard.TargetProperty="Background.Opacity" To="0.2" /> <ColorAnimation Storyboard.TargetName="container" Storyboard.TargetProperty="Background.Color" To="#ffff8000" /> </Storyboard> 这也将首先对颜色进行动画处理,然后对不透明度进行动画处理... 我做错了什么还是这是一个已知问题?如果是这样,是否有任何已知的解决方法? 这其实是你的眼睛欺骗了你。光是一件棘手的事情,它的强度不是线性的(对数或接近平方取决于我们正在讨论的光强度/颜色的哪个方面)。此外,从灰色到橙色的步骤比减少不透明度要短得多,因此您的眼睛比不透明度变化更快地察觉到这种情况发生。 这里有几个深入探讨该主题的链接: https://computergraphics.stackexchange.com/q/1587 https://www.youtube.com/watch?v=LKnqECcg6Gw 为了用您的示例说明这种现象,我更改了您的模板以显示动画正在做什么。在下面的结果中,您可以看到它确实线性地穿过两个值。 <Button Background="#FF272700" Foreground="White" Padding="16,8" HorizontalAlignment="Center" VerticalAlignment="Center"> <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="container" Background="{TemplateBinding Background}" Padding="16,8"> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock Text="{Binding Background.Color, ElementName=container}" /> <TextBlock Grid.Row="1" Text="{Binding Background.Opacity, ElementName=container}" /> </Grid> <!--<ContentPresenter Margin="{TemplateBinding Padding}" />--> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0:0:05" /> </VisualStateGroup.Transitions> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> <Storyboard Changed="Storyboard_Changed"> <DoubleAnimation Storyboard.TargetName="container" Storyboard.TargetProperty="Background.Opacity" To="0.2" /> <ColorAnimation Storyboard.TargetName="container" Storyboard.TargetProperty="Background.Color" To="#ff8000" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Border> </ControlTemplate> </Button.Template> </Button> 解决方法是分别更改动画的速度和/或起点,让它们按照您想要的方式显示。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.