簡體   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