Note that there are some explanatory texts on larger screens.

plurals
  1. POwpf binding in template and on ItemsSource property
    text
    copied!<p>I have the ItemsSource property of a DataGrid bind to a property of my ViewModel!</p> <pre><code>&lt;DataGrid ItemsSource="{Binding Path=ExcelData}" ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" Grid.Row="1" Margin="0 10 0 10" Visibility="{Binding DisplayGridView, Converter={StaticResource booltovisibility}}" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" /&gt; </code></pre> <p>As you can see, the DataGrid has a special header template. </p> <pre><code>&lt;Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"&gt; &lt;Setter Property="VerticalContentAlignment" Value="Center" /&gt; &lt;Setter Property="Background" Value="{x:Static pm:MetroColors.FeatureBrush}" /&gt; &lt;Setter Property="Foreground" Value="White" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="DataGridColumnHeader"&gt; &lt;Border BorderThickness="2" CornerRadius="5" Background="{x:Static pm:MetroColors.FeatureBrush}" BorderBrush="{x:Static pm:MetroColors.FeatureBrush}"&gt; &lt;StackPanel&gt; &lt;ComboBox ItemsSource="{Binding ComboDataSource}" DisplayMemberPath="Text" SelectedValuePath="Name" ext:ComboBoxExtensions.ComboBoxName="{TemplateBinding Content}" SelectionChanged="ComboBox_SelectionChanged" /&gt; &lt;Label Content="{TemplateBinding Content}" /&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Problem : the combobox is not filled.</p> <p>I have this output :</p> <pre><code>System.Windows.Data Error: 40 : BindingExpression path error: 'ComboDataSource' property not found on 'object' ''String' (HashCode=752763509)'. BindingExpression:Path=ComboDataSource; DataItem='String' (HashCode=752763509); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') </code></pre> <p>I am agree with it! there is no property named ComboDataSource on the object binded to the columnheader.</p> <p>How can I bind my combobox to a different source?</p>
 

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