天道酬勤,学无止境

wpf

如何获取资源中元素的引用,WPF?(How to get reference to element in resources, WPF?)

问题 我对 WPF 有问题 - 我对这项智能技术很陌生。 所以问题是: 我有一个窗口。 在这个窗口的资源中,我存储了一个元素 - 例如。 具有唯一键的网格(假设 x:Key="myGrid")。 在这个网格中,我有一个由名称标识的文本框 (x:Name="myTextBox")。 我的窗口只包含一个空的网格(命名为例如 winGrid)。 我以编程方式将 myGrid 设置为 winGrid 的子项。 现在,在运行时,我想获得对 myTextBox 对象的引用。 我花了很多时间在谷歌上搜索,但没有任何效果(FindName 和类似的方法)。 你有什么想法,我必须做些什么才能让球滚动? 这是(伪)代码片段: <Window x:Class="LoginForm.RidicWindow" ...> <Window.Resources> <Grid x:Key="myGrid"> <Border... <Grid... ... <TextBlock x:Name="myTextBlock" Grid.Column="0".../> </Grid> </Grid> </Window.Resources> <Grid x:Name="winGrid"> ... </Grid> 现在我将 myGrid 设置为 winGrid 的子项:(类似于) winGrid.Childrens.Clear(

2021-10-27 04:02:06    分类:技术分享    wpf   reference   resources   element

How can I change (i.e. toggle) the bound, StringFormat property of a WPF control?

I have a WPF TextBox that has it's text value bound in XAML. This works fine and, as expected, when the associated value is loaded to the field, it is formatted as desired. My issue is when the user enters the text field to modify the value, I want to strip away the formatting, and display the raw underlying value. To do this, I tried to set the BindingExpression.ParentBinding.StringFormat property, on the text boxes binding from within a GotFocus event. However, when I tried to set the StringFormat property to an empty string, I got the following exception: Binding cannot be changed after it

2021-10-27 03:57:36    分类:问答    c#   wpf   xaml   string-formatting   code-behind

How to get only modified Items from WPF Data Grid

I have binded a list with Editable WPF DataGrid I want to get only the modified Items from the WPF Data Grid for updation. Please let me know how to do this.

2021-10-27 03:56:16    分类:问答    wpf   binding   wpfdatagrid

如何解决 ItemsPanelTemplate 中 Grid.Row/Column 的错误?(How to defeat a bug with Grid.Row / Column in ItemsPanelTemplate?)

问题 创建了一个简单的附加属性以简化元素模板的绑定。 取而代之的是: <ItemsControl ItemsSource="{Binding Mode=OneWay, Source={StaticResource Points.Grid}}" ItemsPanel="{StaticResource Grid.Panel}"> <ItemsControl.ItemTemplate> <DataTemplate DataType="Point"> <Ellipse Fill="Coral"/> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Grid.Row" Value="{Binding Y}"/> <Setter Property="Grid.Column" Value="{Binding X}"/> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> 你可以这样走: <ItemsControl Grid.Row="1" ItemsSource="{Binding Mode=OneWay, Source={StaticResource Points

2021-10-27 03:50:52    分类:技术分享    wpf   grid   row   attached-properties   itemspaneltemplate

WPF DataTemplate performance

Well the problem here is that if you have one DataTemplate for a type of object, each time the object is present, the DataTemplate will be created, that sounds about right. My problem is that our DataTemplate is sort of heavy AND the app could have around 1000 objects using that DataTemplate. I created a simplistic example where I created 5 Person objects and I bind them to a ListView. The DataTemplate for the Person object is a Grid with a Label and a ContextMenu with 2 MenuItems. For simplicity I just want to concentrate in the MenuItems. Using a memory profiler, I can see that there are a

2021-10-27 03:48:01    分类:问答    wpf   binding

使用带有 IsNavigationTarget 的 Prism 处理嵌套视图,它可以返回 false(Working with nested views using Prism with IsNavigationTarget which can return false)

问题 我正在尝试为以下问题寻找解决方案。 我有一个 WPF 应用程序,我使用 mvvm 和棱镜(最新版本 7)来构建它。 这是我处理的表单/对话框的草稿: MainView 有 region - region1,我根据在 treeview 中选择的内容将 SubViewA 注入 region1。 此视图表示树项内容。 SubViewA 本身有 region - region2,另一个视图 - SubViewB 根据组合框选择注入 region2。 我使用 INavigationAware 来管理对该区域的注入。 因此,要将视图注入我从 MainViewModel 使用的区域,请执行以下操作: _regionManager.RequestNavigate(regionName, viewName, callBack, parameters); 在 SubViewAViewModel 中,我实现了 INavigationAware,为了重用创建的视图,我检查是否创建了每个树项的视图。 为此,我将一个 treeitemId 添加到参数中,然后在 IsNavigationTarget 方法中检查此 ID,如下所示: bool IsNavigationTarget(NavigationContext navigationContext) { // get id parameter from

2021-10-27 03:38:15    分类:技术分享    wpf   region   prism-7   composite-application   region-management

In WPF RichTextBox takes too long to Load when there is no height

I have the following simple wpf program with a RichTextBox. I just try to load a text file into the RichTextBox. The text file is nearly 82KB and it has 4000 lines. But the problem is if you don't specify a Height parameter for the RichTextBox it takes more than 10 seconds to show the window. But if there is a Height parameter then it shows the window with the content instantly. namespace WpfApplication1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); string text = System.IO.File.ReadAllText(@"C:\Users\SSSS\Desktop\WriteLines.txt"); Paragraph p = new

2021-10-27 03:37:36    分类:问答    c#   wpf

如何为自定义用户控件提供数据触发器属性?(How to give Data trigger property for custom usercontrol?)

问题 我已经将 datagrid 的自定义用户控件创建为 CustomDatagrid。 我在另一个用户控件中使用该自定义数据网格作为 DatagridUserControl。 我在 DatagridUserControl 的 CustomDatagrid 中添加了 Textblock。 我在 DatagridUserControl 中为 Textblock 提供了 x:Name。 <GridControl:CustomDatagrid Grid.Row="2" Height="260" Width="640" x:Name="GridTask" BorderThickness="0" FontSize="24" Foreground="White" SelectionChanged="slmGridTask_SelectionChanged" ColumnWidth="*" CanUserResizeColumns="False" Background="Transparent"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid Margin="-50,0,0,0" HorizontalAlignment="Left">

2021-10-27 03:37:04    分类:技术分享    c#   wpf   xaml

在这种情况下,在 wpf 中获取对象的 XY?(get XY of object in wpf for this situation?)

问题 我有一个带有两个或更多对象的Canvas 。 现在,我将这些对象放在一个新的Canvas放置在之前的Canvas 。 然后,我旋转它。 现在,我想知道如何在新的Canvas获取对象的位置,就好像没有新的画布一样。 回答1 您可以使用以下扩展方法来获取一个UIElement相对于另一个UIElement的位置: public static class ExtensionMethods { public static Point GetRelativePosition(this UIElement element, UIElement other) { return element.TransformToVisual(other) .Transform(new Point(0, 0)); } }

2021-10-27 03:28:45    分类:技术分享    wpf   canvas   transform

WPF Combobox Mouse Over

How can I setup a Combobox Style to make it look like this when mouse is hovering over it? Currently, it looks like this: I tried this: <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="White" /> </Trigger> </Style.Triggers> But it did not work. Update, this is what I have when I right-click on the combobox:

2021-10-27 03:26:39    分类:问答    wpf   combobox