Note that there are some explanatory texts on larger screens.

plurals
  1. POXamlWriter.Save loses ItemsSource binding from a ListBox
    primarykey
    data
    text
    <p>I have a custom ContentControl </p> <pre><code>public class DataControl : ContentControl { public List&lt;DataItem&gt; Options { get { return (List&lt;DataItem&gt;)GetValue(OptionsProperty); } set { SetValue(OptionsProperty, value); } } public static readonly DependencyProperty OptionsProperty = DependencyProperty.Register("Options", typeof(List&lt;DataItem&gt;), typeof(DataControl)); public DataControl() { Options = new List&lt;DataItem&gt;(); } public string Label { get { return (string)GetValue(LabelProperty); } set { SetValue(LabelProperty, value); } } // Using a DependencyProperty as the backing store for Label. This enables animation, styling, binding, etc... public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(DataControl)); } public class DataItem { public DataItem(string key, string value) { Key = key; Value = value; } public string Key { get; set; } public string Value { get; set; } } </code></pre> <p>whose template is applied by the following Style:</p> <pre><code>&lt;Style TargetType="{x:Type local:DataControl}" x:Key="DefaultStyle"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:DataControl}"&gt; &lt;StackPanel&gt; &lt;ListBox ItemsSource="{TemplateBinding Options}" &gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Label Content="{Binding Key}" /&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;Label Content="{TemplateBinding Label}" /&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>If I use a XamlWriter to Save this style and then read it back again, the ItemsSource binding is lost, but the Content binding on the Label isn't. </p> <pre><code>Style style = Application.Current.TryFindResource("DefaultStyle") as Style; string s = XamlWriter.Save(style); Style secondStyle = XamlReader.Parse(s) as Style; </code></pre> <p>Is there a way to ensure the ItemsSource binding is serialized correctly or to add it back in easily?</p> <p>This also occurs when trying to get the Style from a ResourceDictionary from another project, e.g.</p> <pre><code>ResourceDictionary styles = new ResourceDictionary(); styles.Source = new Uri(String.Format("pack://application:,,,/StyleCopyTest;component/Styles/{0}Styles.xaml", type)); return styles; </code></pre>
    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.
 

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