简体   繁体   English

在DataTamplate中绑定对象的两个属性

[英]Binding two properties of object in DataTamplate

I have GridControl (Devexpress) with ItemsSource="{Binding Flow}". 我有带有ItemsSource =“ {Binding Flow}”的GridControl(Devexpress)。 I implemented grouping by TagRange column. 我通过TagRange列实现了分组。 I want to change GroupValue. 我想更改GroupValue。

<dxg:GridColumn Header="Tag Range" Binding="{Binding Path=TagRange}" GroupIndex="0" >
    <dxg:GridColumn.GroupValueTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Value}"/>
        </DataTemplate>
    </dxg:GridColumn.GroupValueTemplate>
</dxg:GridColumn>

The text of TextBlock equals TagRange property. TextBlock的文本等于TagRange属性。 How can I bind TextBlock Text property as Name + " " + TagRange . 如何将TextBlock Text属性绑定为Name + " " + TagRange

Flow class: 流类:

public class Flow
{
    public string Name{ get; set; }
    public string TagRange { get; set; }
    ...
}

If you want to do this purely in XAML, use Run elements: 如果只想在XAML中执行此操作,请使用Run元素:

<TextBlock>
    <Run Text="{Binding Name}"/> <Run Text="{Binding TagRange}"/>
</TextBlock>

Alternatively, you could create a composite property in your model / viewmodel and bind to that: 或者,您可以在模型/视图模型中创建一个复合属性并绑定到该属性:

public class Flow
{
    public string Text => $"{Name} {TagRange}";
    // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM