繁体   English   中英

如何在 Expression Blend 4 中编辑 CellTemplate

[英]How to edit CellTemplate in Expression Blend 4

关于在 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>

结果是 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 代码来修复它?

如果是这样,我可能完全偏离了基础,很抱歉不理解,但似乎这个问题过于复杂了所需要的。 CellTemplate 只是任何内容的占位符——在数据网格中,它默认为空,因此您可以在其中放入任何内容 -> 在您的情况下,它是 TextBlock 的占位符。 这就是您需要在 Blend 中编辑的内容,或者您在 CellTemplate 中放置的任何其他控件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM