下面是我不理解在Expression Blend 4编辑电池模板的事情:如何在Expression Blend编辑CellTemplate 4
当我通过XAML手动创建电池模板,代码如下所示:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:leartWPF" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="leartWPF.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<local:GroupDataSource x:Key="GroupDataSourceDataSource" d:IsDataSource="True"/>
</Window.Resources>
<Grid x:Name="LayoutRoot" Margin="0" DataContext="{Binding Source={StaticResource GroupDataSourceDataSource}}">
<DataGrid Margin="0" HeadersVisibility="None" ItemsSource="{Binding GroupExtednenDatas, ElementName=Window}" AutoGenerateColumns="False" RowHeight="25" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" CanUserAddRows="False" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Groups" Width="Auto" IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Width="200"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
导致一个窗口,它看起来或多或少好吗:
当我试图做同样的使用Expression Blend中的菜单,
我结束了下面的代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:leartWPF" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="leartWPF.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<local:GroupDataSource x:Key="GroupDataSourceDataSource" d:IsDataSource="True"/>
<DataTemplate x:Key="MyDataTemplate">
<TextBlock Text="{Binding Name}" Width="200"></TextBlock>
</DataTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot" Margin="0" DataContext="{Binding Source={StaticResource GroupDataSourceDataSource}}">
<DataGrid Margin="0" HeadersVisibility="None" ItemsSource="{Binding GroupExtednenDatas, ElementName=Window}" AutoGenerateColumns="False" RowHeight="25" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" CanUserAddRows="False" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Groups" Width="Auto" IsReadOnly="True" CellTemplate="{DynamicResource MyDataTemplate}" >
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
,显示空单元格不管我把里面的
<DataTemplate x:Key="MyDataTemplate"> :
我做错了什么,或者这是表达式混合错误?如果这是一个错误,我应该如何更改XAML代码来修复它?
据我所见,他们只在模板声明方面有所不同:内联前者,后者是资源。你确定你使用的是相同的代码隐藏吗?附: 'DataGrid' ItemsSource中是否需要输入错字? – 2012-04-10 18:12:07
我真的重复了几次。另外,我用StaticResource替换了DynamicResource,并且它再次运行。这里似乎有一个与DynamicResource相关的问题 – 2012-04-10 18:20:19