/ / Expression Blend 4でCellTemplateを編集する方法 - c#、wpf、xaml、wpfdatagrid、expression-blend

Expression Blend 4でCellTemplateを編集する方法 - c#、wpf、xaml、wpfdatagrid、expression-blend

ここでは、Expression Blend 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"> :

ここに画像の説明を入力

私は何か間違っているのですか、それともこのExpression Blendのバグですか?これがバグの場合は、XAMLコードを変更してそれを修正する必要がありますか?

回答:

回答№1は0

私は完全に基盤から離れているかもしれない、もしそうなら、CellTemplateは何かのためのプレースホルダです - データグリッドではデフォルトでは空ですので、あなたが望むものを置くことができます - >あなたのケースでは"TextBlockのプレースホルダです。これは、Blendで編集する必要があるもの、またはCellTemplateに入れている他のコントロールです。