wpf 相关问题

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

从外部文件在自己的运行空间中显示 wpf 对话框

我有这个概念验证的 powershell 脚本,它将以其当前的形式工作,并将显示一个空白对话框,但以 wpf-ui 库为主题。 如果我更改 $reader = (New-Object System.Xml.XmlNode...

回答 1 投票 0

允许用户将大小调整为负高度/宽度

我正在 WPF 中创建一个类似绘画的工具,并遇到了以下问题,当用户单击绘制的形状(DrawingShape)时,将出现一个带有 8 个拇指的装饰器(矩形的每一侧各一个......

回答 1 投票 0

wpf组合框如何处理PreviewMouseWheel

我想将 MouseWheel 的处理程序添加到 ComboBox,但我不知道如何操作。 原因是我在 ScrollViewer 内的 DataGrid 内的 ComboBox 上遇到滚动问题,请参阅此处,我...

回答 1 投票 0

InvalidOperationException:调度程序处理已暂停,但消息仍在处理中

我们遇到了与此异常有关的多个问题,但我找不到有关问题的真正原因、此错误的所有可能来源以及我们应该避免什么的技术文档...

回答 2 投票 0

MVVM - 当绑定属性不存在时隐藏控件

我想知道如果视图模型中不存在控件绑定的属性,是否可以隐藏视图上的控件。例如,如果我有以下内容: 我想知道如果视图模型中不存在控件绑定的属性,是否可以隐藏视图上的控件。例如,如果我有以下内容: <CheckBox Content="Quote" IsChecked="{Binding Path=IsQuoted}" /> 我可以在 XAML 中检测到视图模型上不存在 IsQuoted 属性,并简单地隐藏该实例中的控件吗? 我本质上是创建一个向导对话框,该对话框在视图模型集合中移动,显示每个视图模型的关联视图。对于集合中的某些视图模型,将存在“IsQuoted”属性,而对于某些视图模型则不存在。 我希望在这些视图之外有一个复选框,当当前视图模型具有该属性时显示,当视图模型不具有该属性时隐藏。所有视图模型都派生自一个公共基类,但我不想通过添加“ShowQuoted”属性等来弄乱基类。 想法?并且,预先感谢... 使用始终返回 Visibility.Visible 的转换器来处理该值存在的情况。通过指定回退值来处理该值不存在的情况。当该属性不存在时,绑定失败并接收后备值。 <Page.DataContext> <Samples:OptionalPropertyViewModel/> </Page.DataContext> <Grid> <Grid.Resources> <Samples:AlwaysVisibleConverter x:Key="AlwaysVisibleConverter" /> </Grid.Resources> <CheckBox Content="Is quoted" IsChecked="{Binding IsQuoted}" Visibility="{Binding IsQuoted, Converter={StaticResource AlwaysVisibleConverter}, FallbackValue=Collapsed}" /> </Grid> public class OptionalPropertyViewModel { public bool IsQuoted { get; set; } } public class AlwaysVisibleConverter : IValueConverter { #region Implementation of IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } #endregion } 我修改了Phil的答案以使TargetNullValue起作用: public class AlwaysVisibleConverter : IValueConverter { public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture) { if (value is null) { // Makes TargetNullValue work. // Apparently TargetNullValue doesn't look at the target directly, but through this converter. return null; } return Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 并且: <CheckBox Content="Is quoted" IsChecked="{Binding IsQuoted}" Visibility="{Binding IsQuoted, Converter={StaticResource AlwaysVisibleConverter}, FallbackValue=Collapsed TargetNullValue=Collapsed}" />

回答 2 投票 0

取消任务后代码未执行

我们将异步命令的执行绑定到导致任务的 ui。另一个命令取消了此任务,但它无法正常工作。 公共类MainWindowViewModel:BaseViewModel {

回答 1 投票 0

WPF 双向绑定会话错误被隐藏

我想将 DataRowView 绑定到窗口上的控件。 初始化代码: ... 行=查询.DefaultView[0]; 数据上下文=行; XAML: ...

回答 1 投票 0

克隆自定义 UserControl C# WPF - 最简单的方法(浅复制)

我想克隆(浅克隆)自定义用户控件,例如: uc按钮 uc; uc按钮 uc2; uc = uc2; 当我这样做时,编译器希望我从画布中删除旧实例(uc)。 使用: Canvas1.Chi...

回答 1 投票 0

在同一时间轴上对两个对象进行动画处理。相继。 WPF

如何在同一时间线但以不同的时间间隔对两个对象的不透明度进行动画处理? 我期待这两个文本元素逐渐淡入,从一个文本框到另一个文本框。相反,Th...

回答 1 投票 0

WPF 在关闭事件中隐藏窗口可防止应用程序终止

又是一个简单的问题。 我使用 WPF 中的一个窗口作为子窗口,我宁愿让“X”按钮隐藏窗口而不是关闭窗口。为此,我有: 私人无效Window_Closing(o...

回答 4 投票 0

获得焦点和 KeyEventArgs

private void TextBox27_GotFocus(对象发送者,RoatedEventArgs e) { Stil53.Begin(); TextBox27.Select(TextBox27.Text.Length, 0); Takvim_Kapat();

wpf
回答 1 投票 0

调整 DataGrid 大小时出现意外的垂直线

我正在使用以下代码使用 DataGrid: 我正在使用以下代码使用 DataGrid: <DataGrid Name="DataGridBids" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HeadersVisibility="Column" Background="#0d4338" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" ItemsSource="{Binding Bids}" AutoGenerateColumns="False" IsReadOnly="True" IsManipulationEnabled="False" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" GridLinesVisibility="None" Margin="0,0,0,0" BorderThickness="0"> <DataGrid.Resources> <Style TargetType="DataGridCell"> <Setter Property="TextBlock.TextAlignment" Value="Center"/> <Setter Property="Background" Value="#0d4338"/> <Setter Property="Foreground" Value="#11b376"/> <Setter Property="BorderThickness" Value="0,0,0,0"/> </Style> </DataGrid.Resources> <DataGrid.Columns> <DataGridTextColumn Header="Agent" Width="*" Binding="{Binding Agent}"/> <DataGridTextColumn Header="Quantity" Width="*" Binding="{Binding Quantity}"/> <DataGridTextColumn Header="Buy" Width="*" Binding="{Binding Price, StringFormat='N2'}"/> </DataGrid.Columns> </DataGrid> 当我打开 DataGrid 时,它的工作方式与我预期的完全一样: 但是当我调整窗口大小时,这些意想不到的白色垂直线不断出现(尽管并非总是如此): 由于某种原因,白线仅显示在第二列和第三列之间,并且始终垂直。 我不知道这是否是 WPF 错误,但无论如何我都想修复它。 任何建议都值得赞赏,谢谢! 渲染一定有什么奇怪的地方。由于您的列都打算具有相同的背景,因此您的样式可以像这样以 DataGridRow 而不是 DataGridCell 为目标(注意:我使用透明,因为 DataGrid 已经具有您想要的背景颜色): <DataGrid.Resources> <Style TargetType="DataGridRow"> <Setter Property="Background" Value="Transparent" /> <Setter Property="TextBlock.TextAlignment" Value="Center" /> <Setter Property="Foreground" Value="#11b376" /> <Setter Property="BorderThickness" Value="0,0,0,0" /> </Style> </DataGrid.Resources> 这消除了我在调整网格大小时看到的任何奇怪的锯齿,但我无法准确重现您所显示的内容。

回答 1 投票 0

将可绑定属性与命令同步

有没有办法在属性以指定的绑定延迟发生变化时执行命令? 作为示例,让我们使用具有 IsChecked 属性且 Delay=1000(1 秒)的 CheckBox 和调用...的 Command

回答 1 投票 0

如何为数据绑定组合框预定义组合框项?

我想允许用户选择串口的波特率。 我创建了一个与串口波特率绑定的文本框,如下所示,它可以工作。 我想允许用户选择串口的波特率。 我创建了一个与串口波特率绑定的文本框,如下所示,它可以工作。 <TextBox x:Name="tbbaudRate" Text="{Binding SerialPort.BaudRate}" /> 我的问题是,有效波特率的设置是有限的。有效波特率为 { 75, 110, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 }。我想将文本框更改为列出有效波特率值的组合框。 这就是我所做的。 <ComboBox x:Name="tbbaudRate" Text="{Binding SerialPort.BaudRate}" > <ComboBoxItem Content="75"/> <ComboBoxItem Content="110"/> <ComboBoxItem Content="300"/> <ComboBoxItem Content="1200"/> <ComboBoxItem Content="2400"/> <ComboBoxItem Content="4800"/> <ComboBoxItem Content="9600"/> <ComboBoxItem Content="19200"/> <ComboBoxItem Content="38400"/> <ComboBoxItem Content="57600"/> <ComboBoxItem Content="115200"/> </ComboBox> 虽然这有效,但我几乎没有问题。 当我第一次加载窗口时,未选择波特率的默认值(9600)。 这看起来不太优雅。实现这一目标的最佳方法是什么? 供参考,这是我的串口类。也像上面的代码一样丑陋。我使用 resharper 自动生成 notificationpropertychange 代码。 class SerialComm : INotifyPropertyChanged { private int[] ValidBaudRate = new[] { 75, 110, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 }; //Dont know how to use this private int[] ValidDataBits = new[] { 5, 6, 7, 8, 9 }; //Dont know how to use this private SerialPort _serialPort; public SerialComm() { _serialPort = new SerialPort(); } public SerialPort SerialPort { get { return _serialPort; } set { _serialPort = value; OnPropertyChanged("SerialPort"); SerialPort.GetPortNames(); } } #region Autogenerate by resharper public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } #endregion } 像这样改变你的组合框: <ComboBox Name="comboBox1" Width="120" ItemsSource="{Binding Path=ValidBaudRateCollection}"> <ComboBox.ItemTemplate> <DataTemplate> <Label Content="{Binding }"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> 将这些添加到您的SerialComm课程中: public ObservableCollection<int> ValidBaudRateCollection; public SerialComm() { this.ValidBaudRateCollection = new ObservableCollection<int>(this.ValidBaudRate); _serialPort = new SerialPort(); } 最后将它们添加到您的Window中的某个位置(例如构造函数) SerialComm s = new SerialComm(); comboBox1.DataContext = s; comboBox1.ItemsSource = s.ValidBaudRateCollection; comboBox1.SelectedIndex = 6; 注意: 这样您就可以绑定组合框值,但是将 ObservableCollection 添加到似乎位于另一层的类中可能在架构上不正确。 要使“9600”成为默认波特率,您需要添加以下行 myComboBox.SelectedIndex = 7; 9600 排在第七位 希望有帮助... 旧线程,但让我走上了正轨: 通过添加 SelectedValuePath="Content" 并将其保存到 SelectedValue 来解决它。 <ComboBox SelectedValue="{Binding LaserBaudRate, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="Content"> <ComboBoxItem Content="75" /> <ComboBoxItem Content="110" /> <ComboBoxItem Content="300" /> <ComboBoxItem Content="1200" /> <ComboBoxItem Content="2400" /> <ComboBoxItem Content="4800" /> <ComboBoxItem Content="9600" /> <ComboBoxItem Content="19200" /> <ComboBoxItem Content="38400" /> <ComboBoxItem Content="57600" /> <ComboBoxItem Content="115200" /> </ComboBox> 只需添加: private int selectedBaudRate; public Constructor() { SelectedBaudRate = Properties.Settings.Default.SelectedBaudRate; } public int SelectedBaudRate { get => selectedBaudRate; set { if (value != selectedBaudRate) { OnPropertyChanging(); selectedBaudRate = value; Properties.Settings.Default.SelectedBaudRate = value; OnPropertyChanged(); } } } <ComboBox Width="80" ItemsSource="{Binding AvailableBaudRate}" SelectedValue="{Binding SelectedBaudRate, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />

回答 4 投票 0

wpf 将所有滑块“ IsEnabledProperty 绑定到数组中

首先我是wpf新手和菜鸟程序员...我有一个userControl显示超过100个滑块,我想在数组中管理它们的“IsEnabledProperty”,我正在考虑使用绑定expre...

回答 1 投票 0

WPF:ToggleButton 的 ControlTemplate 绑定“IsChecked”属性时会导致 App 崩溃

编辑:要重现此错误,您必须将 ToggleButton 放入“TabControl”的“非第一个”TabItem 中:],如下所示: 测试 编辑:要重现此错误,您必须将 ToggleButton 放在“TabControl”的“非第一个”TabItem中:],如下所示: <TabControl> <TabItem> <Label>Test</Label> </TabItem> <TabItem> <ToggleButton IsChecked="{Binding IsBusy, Mode=TwoWay}" Style="{StaticResource SwitchButton}" /> </TabItem> </TabControl> 这是我的自定义Style ToggleButton <Style x:Key="SwitchButton" TargetType="{x:Type ToggleButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Viewbox> <Border x:Name="_Border" Width="40" Height="20" Background="#FFFFFFFF" CornerRadius="10"> <Border.Effect> <DropShadowEffect Direction="0" Opacity="0.3" ShadowDepth="0.5" /> </Border.Effect> <Ellipse x:Name="_Ellipse" Margin="2,1,2,1" HorizontalAlignment="Stretch" Fill="#FFFFFFFF" Stretch="Uniform" Stroke="Gray" StrokeThickness="0.2"> <Ellipse.Effect> <DropShadowEffect BlurRadius="10" Direction="260" Opacity="0.3" ShadowDepth="1" /> </Ellipse.Effect> </Ellipse> </Border> </Viewbox> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Checked"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="_Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#12a5fd" Duration="0:0:0.1" /> <ThicknessAnimation Storyboard.TargetName="_Ellipse" Storyboard.TargetProperty="Margin" To="20 1 2 1" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Unchecked"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="_Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0.1" /> <ThicknessAnimation Storyboard.TargetName="_Ellipse" Storyboard.TargetProperty="Margin" To="2 1 2 1" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 当 IsChecked 未绑定时,它按预期工作: 未选中: 已检查: 但是,当我将 IsChecked 属性绑定到我的视图模型时,应用程序将崩溃。错误消息显示“System.InvalidOperationException:在 System.Windows.Controls.ControlTemplate 的名称范围中找不到名称”。 我发现了一个类似的问题,我按照接受的答案建议,使用Storyboard.Target代替: Storyboard.Target="{Binding ElementName=_Border}" 使用“Storyboard.Target”确实可以消除问题,应用程序可以正常打开。但是,当我检查 ToggleButton 时,它保持未选中状态。 解决方案是将EventTrigger中的ControlTemplate替换为Trigger: <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="_Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#12a5fd" Duration="0:0:0.1" /> <ThicknessAnimation Storyboard.TargetName="_Ellipse" Storyboard.TargetProperty="Margin" To="20 1 2 1" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="_Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0.1" /> <ThicknessAnimation Storyboard.TargetName="_Ellipse" Storyboard.TargetProperty="Margin" To="2 1 2 1" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> 类似的问题是这里

wpf
回答 1 投票 0

WPF圆角文本框

我不懂WPF,现在正在学习。我正在寻找 WPF 中的圆角 TextBox。所以我搜索了Google并找到了一段XAML: 我不了解WPF,现在正在学习。我在 WPF 中寻找圆角TextBox。所以我在Google上搜索并找到了一块XAML: <!–Rounded Corner TextBoxes–> <ControlTemplate x:Key=”RoundTxtBoxBaseControlTemplate” TargetType=”{x:Type Control}”> <Border Background=”{TemplateBinding Background}” x:Name=”Bd” BorderBrush=”{TemplateBinding BorderBrush}” BorderThickness=”{TemplateBinding BorderThickness}” CornerRadius=”6″> <ScrollViewer x:Name=”PART_ContentHost”/> </Border> <ControlTemplate.Triggers> <Trigger Property=”IsEnabled” Value=”False”> <Setter Property=”Background” Value=”{DynamicResource {x:Static SystemColors.ControlBrushKey}}” TargetName=”Bd”/> <Setter Property=”Foreground” Value=”{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}”/> </Trigger> <Trigger Property=”Width” Value=”Auto”> <Setter Property=”MinWidth” Value=”100″/> </Trigger> <Trigger Property=”Height” Value=”Auto”> <Setter Property=”MinHeight” Value=”20″/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> 所以请告诉我将其粘贴到哪里XAML。请详细帮助我。我是 WPF 的初学者。 @Smolla 在对 @Daniel Casserly 的回答的评论中给出了更好的答案: <TextBox Text="TextBox with CornerRadius"> <TextBox.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="3"/> </Style> </TextBox.Resources> </TextBox> 如果您希望 TextBox 和 ListBox 的所有边框都有圆角,请将样式放入您的 Window 或 App 中<Resources>。 在 WPF 中,您可以修改或重新创建控件的外观。因此,如果您的示例他们所做的是通过修改现有 ControlTemplate 的 TextBox 来更改文本框的外观。因此,要查看和探索这段代码,只需使用下面的代码 <Window x:Class="WpfApplication4.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.Resources> <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}"> <Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="Black" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> <ScrollViewer x:Name="PART_ContentHost"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> <Trigger Property="Width" Value="Auto"> <Setter Property="MinWidth" Value="100"/> </Trigger> <Trigger Property="Height" Value="Auto"> <Setter Property="MinHeight" Value="20"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources> <Grid> <TextBox Template="{StaticResource TextBoxBaseControlTemplate}" Height="25" Margin="5"></TextBox> </Grid> 因此,我们在窗口的资源部分声明了一个静态资源,并在 Template 的 TextBox 属性中使用了 Resource TextBoxBaseControlTemplate 作为 Template="{StaticResource TextBoxBaseControlTemplate}" 。 自定义 WPF 控件的模板只需参考此文档即可获得想法 http://msdn.microsoft.com/en-us/magazine/cc163497.aspx 您可以使用以下样式将所有文本框更改为圆角: <Style TargetType="{x:Type TextBox}"> <Style.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="3" /> </Style> </Style.Resources> </Style> 受到以下答案的启发:https://stackoverflow.com/a/13858357/3387453 只需将文本框的 BorderThickness 设置为零即可在文本框周围添加边框。 <Border BorderThickness="1" BorderBrush="Black" CornerRadius="10" Padding="2" HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBox Text="Hello ! " BorderThickness="0"/> </Border> 输出如图所示! 这个问题在 msdn 上得到了很好的讨论: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/549775ed-1c2a-4911-9078-d9c724294fb3/ 尝试那里的解决方案,它们非常详细,并且足够详细,让您知道将代码放在哪里。 您可以使用附加属性来设置TextBox边框半径(同样适用于按钮)。 为附加属性创建类 public class CornerRadiusSetter { public static CornerRadius GetCornerRadius(DependencyObject obj) => (CornerRadius)obj.GetValue(CornerRadiusProperty); public static void SetCornerRadius(DependencyObject obj, CornerRadius value) => obj.SetValue(CornerRadiusProperty, value); public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(nameof(Border.CornerRadius), typeof(CornerRadius), typeof(CornerRadiusSetter), new UIPropertyMetadata(new CornerRadius(), CornerRadiusChangedCallback)); public static void CornerRadiusChangedCallback(object sender, DependencyPropertyChangedEventArgs e) { Control control = sender as Control; if (control == null) return; control.Loaded -= Control_Loaded; control.Loaded += Control_Loaded; } private static void Control_Loaded(object sender, EventArgs e) { Control control = sender as Control; if (control == null || control.Template == null) return; control.ApplyTemplate(); Border border = control.Template.FindName("border", control) as Border; if (border == null) return; border.CornerRadius = GetCornerRadius(control); } } 然后您可以使用附加属性语法来设置多个文本框的样式,而无需重复样式: <TextBox local:CornerRadiusSetter.CornerRadius="10" /> <TextBox local:CornerRadiusSetter.CornerRadius="5, 0, 0, 5" /> <TextBox local:CornerRadiusSetter.CornerRadius="10, 4, 18, 7" /> 以困难的方式去做。 在 Visual Studio 中创建一个新的空 WPF 项目。将 TextBox 添加到主 Window。然后将鼠标放在 TextBox 上,右键单击并选择 编辑模板、编辑副本...。在出现的对话框中,选择应用于全部和此文档。 您现在拥有 TextBox 模板的副本。现在看看名称为 Border 的 border。只需添加一个 CornerRadius 即可。 接下来将此代码复制/粘贴到您的App.xaml中的/Application/Application.Resources/ResourceDictionary中。 它比其他解决方案需要更多的时间,它更复杂,但更干净,一旦你掌握了这个过程,你就可以使用 WPF 做任何你想做的事情。 这读起来很有趣。

回答 7 投票 0

RelayCommand(MVVM Toolkit)简单Demo讲解

您好,stackoverflow 社区, 我是 MVVM 主题的新手,但能够了解一些基础知识。我编写了一些教程并实现了我自己的 RealyCommand 和 ViewModelBase。 我有我的屁股...

回答 1 投票 0

WPF DataGrid 添加类变量名称的列,无法获取单元格内容

我正在编写一个程序,需要以类似网格的格式提供信息,用户指定列数(为此目的,我称之为轨道)和行数(我称之为段......)

回答 1 投票 0

WPF TextBox为所有控件设置通用的StringFormat

是否可以为项目中的所有(或部分)文本框设置 Binding 属性的 StringFormat ?是的,我可以写一些类似的东西 是否可以为项目中的所有(或部分)文本框设置 Binding 属性的 StringFormat ?是的,我可以写类似的东西 <TextBox x:Name="SetPosition" Style="{StaticResource TextBoxSmallStyle}" Text="{Binding SetPosition, Mode=TwoWay, StringFormat='{}{0:#0.0}'}" /> 但是为许多相同的文本框设置它太无聊了)))如你所见,我使用的样式包括高度,宽度等。我无法覆盖样式中的绑定属性,因为需要将此样式与任何绑定路径属性一起使用,但绑定只能完全覆盖。 哪里有解决方法? 附:我已经使用的不是标准 TextBox,而是覆盖了我的特殊功能的控件。我可以覆盖 Binding 以使用组件的代码隐藏吗? 我对在“查看”时需要“特殊”处理的属性使用(可重用)“功能”代码;例如 public string FirstName { get; set; } public string LastName { get; set; } public string FullName => this.FirstName + " " + this.LastName; ... TextBlock Text={Binding FullName} ...

回答 1 投票 0

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