Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting XAML property value into user control from a consumer view
    primarykey
    data
    text
    <p>I have a custom UserControl that contains a grid ...I wish to set the <code>ItemsSource</code> property of that grid by xaml code of of a data template in a resource dictionary... then I have used dependency property... this is my implementation...</p> <pre><code>public partial class MyControlGrid : UserControl { // Dependency Property public static readonly DependencyProperty MyItemSourceProperty = DependencyProperty.Register("MyItemSource", typeof(ICollectionView), typeof(MyControlGrid), new FrameworkPropertyMetadata(null, OnMyItemSourcePropertyChanged)); IDictionary&lt;string, string&gt; _columns = new Dictionary&lt;string, string&gt;(); private static void OnMyItemSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { // When the color changes, set the icon color PlayButton MyControlGrid muc = (MyControlGrid)obj; ICollectionView value = (ICollectionView)args.NewValue; if (value != null) { muc.MyGridControl.ItemsSource = value; } } public ICollectionView MyItemSource { get { return (ICollectionView)GetValue(MyItemSourceProperty); } set { SetValue(MyItemSourceProperty, value); //OnTargetPowerChanged(this, new DependencyPropertyChangedEventArgs(TargetPowerProperty, value, value)); // Old value irrelevant. } } public MyControlGrid() { InitializeComponent(); } } </code></pre> <p>this is the user control xaml code</p> <pre><code>&lt;UserControl x:Class="GUI.Design.Templates.MyControlGrid" Name="MyListControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfTkit="http://schemas.microsoft.com/wpf/2008/toolkit" xmlns:Templates="clr-namespace:Emule.GUI.Design.Templates"&gt; &lt;StackPanel&gt; &lt;WpfTkit:DataGrid ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Templates:MyControlGrid}}, Path=MyItemSource}" x:Name="MyGridControl" &lt;StackPanel&gt; </code></pre> <p>this is the binding path expression I use</p> <pre><code>&lt;basic:MyControlGrid MyItemSource="{Binding MyDataContextVisibleCollection}"/&gt; </code></pre> <p>this dont work and wpf output window dont show me any errors </p> <p>note that, naturally, if I bind this directly in the user controls work fine</p> <pre><code>&lt;WpfTkit:DataGrid ItemsSource="{Binding MyDataContextVisibleCollection}" </code></pre> <p>Waths I wrong?</p> <p>thanks</p> <p>p.s. sorry for my english</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload