English 中文(简体)
表达式混合中的多级网格
原标题:Multi level grid in Expression Blend

在过去的几天里,我一直在玩Expressions Blend 4,我开始掌握它。我最近才开始玩数据绑定,发现它非常简单和强大。出于原型设计的目的,没有比这更好的应用了。

我目前正在制作一个具有潜在多级网格的Silverlight屏幕的原型。有什么方法可以用Blend做到这一点吗?我尝试创建一个多级数据示例(我向集合数据添加了一个集合数据),并将其拖到数据网格中。只有第一关出现了。

如有任何帮助,我们将不胜感激。

最佳回答

可以使用网格作为面板的ItemsControl,然后在ItemTemplate中使用另一个ItemsControl,并使用另一网格将其绑定到第二级数据。使用ItemsControl,您可以对事物的显示方式进行大量控制,而不仅仅是使用网格。

If you need something that looks like this: Multi-level Binding

以下是实现这一目标的方法:

  1. 将多级示例数据源添加到Blend项目

  2. 将ItemsControl添加到布局根元素

  3. 将ItemsControl.ItemsSource属性绑定到父级

  4. Create an empty item template using this option: Item Template/Create Empty

  5. 在项目模板中,创建希望第二级具有的结构。在我的示例中,结构如下所示:

  6. 将每个子元素绑定到父集合的项中的属性,如网格的标题。

  7. 将项内部的DataGrid绑定到子集合。

最终结果将是一个项目列表,每个项目将包含一个StackPanel、一个内部有TextBlock的Border和一个绑定到子数据的DataGrid。

此示例的XAML如下所示:

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.SampleDataSource" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" mc:Ignorable="d"
        x:Class="ASD_Answer005.MainPage" d:DesignWidth="703" d:DesignHeight="435">

        <UserControl.Resources>
            <SampleData:SampleDataSource x:Key="SampleDataSource" d:IsDataSource="True"/>
            <DataTemplate x:Key="ChildDataTemplate">
                <StackPanel Orientation="Vertical">
                    <Border BorderThickness="0,0,0,2" BorderBrush="Black" Padding="5">
                        <TextBlock TextWrapping="Wrap" Text="{Binding CategoryName}" FontSize="26.667" Height="39"/>
                    </Border>
                    <sdk:DataGrid ItemsSource="{Binding ChildCollection}" BorderThickness="0"/>
                </StackPanel>
            </DataTemplate>
        </UserControl.Resources>
        <d:DataContext>
            <Binding Source="{StaticResource SampleDataSource}"/>
        </d:DataContext>
        <UserControl.DataContext>
            <Binding Source="{StaticResource SampleDataSource}"/>
        </UserControl.DataContext>

        <Grid x:Name="LayoutRoot" Background="White">
            <ScrollViewer HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0" Padding="0">
                <StackPanel Orientation="Vertical" Width="703">
                    <ItemsControl ItemsSource="{Binding ParentCollection}" ItemTemplate="{StaticResource ChildDataTemplate}"/>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </UserControl>

我希望这能有所帮助。

问题回答

暂无回答




相关问题
split video and keep it running [closed]

any one can give me a hind how to split video (and can be played in separeat parts) ,by split here I mean to split it to 4 parts for example and each part can be running (paying)

Triggering animation inside a control

I am doing some transition animation using WPF and Blend 3. I have two outer usercontrols which is what I want the transition effect to happen on. Using Blend I can make this effect. The problem is ...

How to exit full-screen mode in Expression Blend

Somehow, Expression Blend has entered full-screen mode (no window chrome), but I can still minimize/maximize/restore/move through the taskbar button. I don t see any menu options for full-screen mode,...

Display images from folder with Silverlight(Blend)

I have a network directory that has a dump of all employee pics here at our company. The images are named FirstnameLastinitial.jpg. I ultimately am trying to build a photo browser of these pics in ...

热门标签