在 silverlight 中将行为绑定到数据模板的数据上下文

发布于 2025-01-04 03:11:47 字数 5878 浏览 2 评论 0原文

我有一个 DataTemplate:

  <Style x:Key="SalesmanDestinyReportListBoxStyle" TargetType="ListBox">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <ItemsPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <telerik:RadGridView x:Name="grdSalesmanDestinyReport" Width="180" SelectionMode="Single" IsReadOnly="False" IsFilteringAllowed="True"
                     VerticalAlignment="Stretch" RowIndicatorVisibility="Collapsed" HorizontalAlignment="Stretch"
                     CanUserDeleteRows="False" CanUserInsertRows="False" CanUserReorderColumns="False" ItemsSource="{Binding Scores}" AutoGenerateColumns="False">
                           <i:Interaction.Behaviors>
                                <Binding:ColumnGroupsBehavior>
                                    <Binding:ColumnGroupsBehavior.CommonHeaders>
                                        <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />
                                    </Binding:ColumnGroupsBehavior.CommonHeaders>
                                </Binding:ColumnGroupsBehavior>
                            </i:Interaction.Behaviors>
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Current}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Current}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Destiny}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Destiny}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Best}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Best}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>

                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

这里是一个源类:

public class SalesmanDestinyReport
    {
        [DataMember]
        public List<Score> Scores { get; set; }

        [DataMember]
        public string SalesmanName { get; set; }
    }

并且我对这段代码有问题:

                       <i:Interaction.Behaviors>
                            <Binding:ColumnGroupsBehavior>
                                <Binding:ColumnGroupsBehavior.CommonHeaders>
                                    <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />
                                </Binding:ColumnGroupsBehavior.CommonHeaders>
                            </Binding:ColumnGroupsBehavior>
                        </i:Interaction.Behaviors>

问题是我无法将 SalesmanName 属性传递给

   <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />

我认为没有必要解释 CommonHeader 是什么,因为问题我相信位于另一个地方,但以防万一:

http://blogs.telerik.com/pavelpavlov/posts/09-12-04/adding-additional-power-to-radgridview-for-silverlight-with-attached-behaviors.aspx

我需要在绑定声明中更改哪些内容才能显示 SalesmanName ?

I have a DataTemplate:

  <Style x:Key="SalesmanDestinyReportListBoxStyle" TargetType="ListBox">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <ItemsPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <telerik:RadGridView x:Name="grdSalesmanDestinyReport" Width="180" SelectionMode="Single" IsReadOnly="False" IsFilteringAllowed="True"
                     VerticalAlignment="Stretch" RowIndicatorVisibility="Collapsed" HorizontalAlignment="Stretch"
                     CanUserDeleteRows="False" CanUserInsertRows="False" CanUserReorderColumns="False" ItemsSource="{Binding Scores}" AutoGenerateColumns="False">
                           <i:Interaction.Behaviors>
                                <Binding:ColumnGroupsBehavior>
                                    <Binding:ColumnGroupsBehavior.CommonHeaders>
                                        <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />
                                    </Binding:ColumnGroupsBehavior.CommonHeaders>
                                </Binding:ColumnGroupsBehavior>
                            </i:Interaction.Behaviors>
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Current}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Current}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Destiny}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Destiny}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>

                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Best}" IsReadOnly="True"
                             Header="{Binding Current}" Width="60">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Best}">

                                            </TextBlock>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>

                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

here is a source class:

public class SalesmanDestinyReport
    {
        [DataMember]
        public List<Score> Scores { get; set; }

        [DataMember]
        public string SalesmanName { get; set; }
    }

and I have a problem with this piece of code:

                       <i:Interaction.Behaviors>
                            <Binding:ColumnGroupsBehavior>
                                <Binding:ColumnGroupsBehavior.CommonHeaders>
                                    <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />
                                </Binding:ColumnGroupsBehavior.CommonHeaders>
                            </Binding:ColumnGroupsBehavior>
                        </i:Interaction.Behaviors>

The problem is that I can't pass SalesmanName property to

   <Binding:CommonHeader StartColumnIndex="0" Caption="{Binding Path=DataContext.SalesmanName,ElementName=grdSalesmanDestinyReport}" ColumnSpan="3" />

I think that there is no need to explain wthat's the CommonHeader, because the problem I believe lays in another place, but just in case:

http://blogs.telerik.com/pavelpavlov/posts/09-12-04/adding-additional-power-to-radgridview-for-silverlight-with-attached-behaviors.aspx

What I need to change in my binding declaration to display SalesmanName ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤还要旧人安 2025-01-11 03:11:47

从头开始 - Silverlight 4 不支持样式设置器中的绑定(此功能现已在 SL5 中提供)。对于 SL4,有一个解决方法: SetterValueBindingHelper

From scratch - Silverlight 4 does not support bindings in Style Setters (this functionality is now available in SL5). For SL4 there is a workaround: SetterValueBindingHelper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文