【问题标题】:Appending text in Silverlight XAML在 Silverlight XAML 中附加文本
【发布时间】:2012-09-06 13:11:01
【问题描述】:

嗨,

我有一个绑定到项目列表的 Telerik 组合框。它显示它们很好。我希望更改的只是将另一个对象的属性附加到组合框中字符串的开头。

目前,组合框显示"ListOfItems.Name",我希望它显示"Object.Property --- ListOfItems.Name"

   <telerik:RadComboBox x:Name="radComboBox" ItemsSource="{Binding ListOfItems}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedName, Mode=TwoWay}"/>

类似的东西

   <telerik:RadComboBox x:Name="radComboBox" ItemsSource="{Binding ListOfItems}" DisplayMemberPath="String.Append(Object.Property --- Name)" SelectedItem="{Binding SelectedName, Mode=TwoWay}"/>

如何在我的 XAML 代码中执行此操作?

【问题讨论】:

    标签: c# silverlight xaml combobox telerik


    【解决方案1】:

    我不完全确定我理解你想要做什么,但如果我理解正确,你必须使用 RadComboBox 的 ItemTemplate 属性:

    <telerik:RadComboBox x:Name="radComboBox"
                     ItemsSource="{Binding ListOfItems}"
                     SelectedItem="{Binding SelectedName, Mode=TwoWay}">
    <telerik:RadComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Object.Property"></TextBlock>
                <TextBlock Text=" --- "></TextBlock>
                <TextBlock Text="{Binding Name}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </telerik:RadComboBox.ItemTemplate>
    

    【讨论】:

    • 这不起作用,因为“”的绑定没有显示(它只打印裸字符串“Object .Property”使用您的示例)。
    • 想通了 - 必须在第二个绑定中重置 DataContext! DataContext="{Binding Context}" 她工作了。非常感谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多