I was wondering something: if you c开发者_Python百科reate a template under a control (like datagrid), can you always put everything you make under the window.resources? Will give an example:
<Grid Background="DarkGray">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<DataGrid Name="dgFruit" ItemsSource="{Binding}" AutoGenerateColumns="false" ItemTemplate="{StaticResource datagrid}" >
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader">
<Setter Property="Content" Value="{Binding Path=Number}" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Name}" Header="Name"/>
<DataGridTextColumn Binding="{Binding Path=Color}" Header="Color"/>
<DataGridCheckBoxColumn Binding="{Binding Path=Mjummy}" Header="Mjummy"/>
<DataGridTextColumn Binding="{Binding Path=Number}" Header="Number"/>
<DataGridTextColumn Binding="{Binding Path=Pits.Count}" Header="Pits"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
Can you make a datatemplate of everything from <DataGrid.RowHeaderStyle>
to </DataGrid.Columns>
? And if so, could you tell how?
Thanks in advance
That's not something i'd put in a template, but rather in a style, and yes, this style can be put in the resources.
Yes.
It's really important to know how WPF finds resources. When it's trying to find a resource, it first looks in the current object's resource dictionary. If the resource isn't found, then it looks in its container's resource dictionary. It does this recursively, until it reaches an object that has no container (i.e. is a Window), in which case it looks in the application's resource dictionary, and then, finally, give up and tell you that the resource can't be found.
精彩评论