ItemsControl - ItemsControl.ItemContainerStyle中的绑定 [英] ItemsControl - Binding in ItemsControl.ItemContainerStyle

查看:68
本文介绍了ItemsControl - ItemsControl.ItemContainerStyle中的绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ItemsContainerStyle中绑定它似乎没有工作。  这是我的代码:



这是绑定的DataItem:

 public class DataItem 
{
public DataItem(string title,string image,string row,string column,string rowSpan,string columnSpan)
{
Title = title;
Image = image;
行=行;
Column = column;
RowSpan = rowSpan;
ColumnSpan = columnSpan;
}

公共字符串标题
{
get;
私人套装;
}
公共字符串图片
{
get;
私人套装;
}
公共字符串行
{
get;
私人套装;
}
公共字符串列
{
get;
私人套装;
}
公共字符串RowSpan
{
get;
私人套装;
}
公共字符串ColumnSpan
{
get;
私人套装;
}

}


这是XAML:


< pre class ="prettyprint">< Grid Grid.Row =" 1">
< Grid.Background>
< ImageBrush ImageSource =" /Images/Blue_BkgdGrid1080p.jpg"伸展= QUOT; UniformToFill" />
< /Grid.Background>
< ItemsControl ItemsSource =" {Binding Items}">
< ItemsControl.ItemsPanel>
< ItemsPanelTemplate>
< Grid>
< Grid.RowDefinitions>
< RowDefinition />
< RowDefinition />
< RowDefinition />
< /Grid.RowDefinitions>
< Grid.ColumnDefinitions>
< ColumnDefinition />
< ColumnDefinition />
< ColumnDefinition />
< ColumnDefinition />
< ColumnDefinition />
< /Grid.ColumnDefinitions>
< / Grid>
< / ItemsPanelTemplate>
< /ItemsControl.ItemsPanel>
< ItemsControl.ItemTemplate>
< DataTemplate>
< Grid Margin =" 5,0,10,5"背景= QUOT;#FF3B3B3B"的Horizo​​ntalAlignment = QUOT;拉伸" VerticalAlignment = QUOT;顶部和QUOT;>
< Image Stretch =" UniformToFill" Source =" {Binding Image}" />
< / Grid>
< / DataTemplate>
< /ItemsControl.ItemTemplate>
< ItemsControl.ItemContainerStyle>
< Style TargetType =" ContentPresenter">
< Setter Property =" Grid.Column"值=" {Binding Column}" />
< Setter Property =" Grid.Row"值=" {Binding Row}" />
< Setter Property =" Grid.RowSpan" Value =" {Binding RowSpan}" />
< Setter Property =" Grid.ColumnSpan" Value =" {Binding ColumnSpan}" />
< / Style>
< /ItemsControl.ItemContainerStyle>

< / ItemsControl>
<! - < GridView.ItemTemplate>
< DataTemplate>
< Grid Margin =" 5,0,10,5"高度= QUOT; 100"宽度= QUOT; 100"背景= QUOT;#FF3B3B3B"的Horizo​​ntalAlignment = QUOT;拉伸" VerticalAlignment = QUOT;顶部和QUOT;>
< Image Stretch =" UniformToFill" Source =" {Binding Image}" />
< / Grid>
< / DataTemplate>
< /GridView.ItemTemplate> - >
< / Grid>

解决方案

< blockquote>实际上整个ItemsContol.ItemContainerStyle都没有被使用.......


I am trying to bind inside the ItemsContainerStyle and it does not seem to be working.  Here is my code:

Here is the DataItem that is being bound:

 public class DataItem
    {
        public DataItem(string title, string image, string row, string column, string rowSpan, string columnSpan)
        {
            Title = title;
            Image = image;
            Row = row;
            Column = column;
            RowSpan = rowSpan;
            ColumnSpan = columnSpan;
        }

        public string Title
        {
            get;
            private set;
        }
        public string Image
        {
            get;
            private set;
        }
        public string Row
        {
            get;
            private set;
        }
        public string Column
        {
            get;
            private set;
        }
        public string RowSpan
        {
            get;
            private set;
        }
        public string ColumnSpan
        {
            get;
            private set;
        }
        
    }

Here is the XAML:

 <Grid Grid.Row="1">
            <Grid.Background>
                <ImageBrush ImageSource="/Images/Blue_BkgdGrid1080p.jpg" Stretch="UniformToFill"/>
            </Grid.Background> 
            <ItemsControl ItemsSource="{Binding Items}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                </Grid>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="5,0,10,5"  Background="#FF3B3B3B" HorizontalAlignment="Stretch"  VerticalAlignment="Top">
                            <Image Stretch="UniformToFill" Source="{Binding Image}"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="ContentPresenter">
                        <Setter Property="Grid.Column" Value="{Binding Column}"/>
                        <Setter Property="Grid.Row" Value="{Binding Row}"/>
                        <Setter Property="Grid.RowSpan" Value="{Binding RowSpan}"/>
                        <Setter Property="Grid.ColumnSpan" Value="{Binding ColumnSpan}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>

            </ItemsControl>
            <!--<GridView.ItemTemplate>
                <DataTemplate>
                <Grid Margin="5,0,10,5" Height="100" Width="100" Background="#FF3B3B3B" HorizontalAlignment="Stretch"  VerticalAlignment="Top">
                    <Image  Stretch="UniformToFill" Source="{Binding Image}"/>
                </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>-->
        </Grid>

解决方案

Actually the whole ItemsContol.ItemContainerStyle is not getting used at all.......


这篇关于ItemsControl - ItemsControl.ItemContainerStyle中的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆