0

私はこのようなXAMLを持っています。基本的には、異なるプロパティにバインドする複数の文字列を連結します。何らかの理由で、VM上の別のプロパティを公開して単一のプロパティとして使用したくないとしましょう。

それをよりコンパクトにする他のXAMLバインド方法はありますか?

<StackPanel Grid.Column="1" Orientation="Horizontal">
    <TextBlock Text="Added by " FontSize="10" Foreground="#2C2C2C" />
    <TextBlock Text="{Binding Document.MEMUser.UserName}" Foreground="#2C2C2C" FontSize="10" />
    <TextBlock Text=" on " FontSize="10" Foreground="#2C2C2C"/>
    <TextBlock Text="{Binding CreatedOn, Converter={StaticResource DateTimeToStringConverter}}" Foreground="#2C2C2C" FontSize="10" />
    <!--BIND COMMANDS TO PARENT ViewModel to process operations-->
    <Button Content="Delete" Command="{Binding DataContext.DeleteCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
    <Button Content="Download" Command="{Binding DataContext.DownloadCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
</StackPanel>
4

2 に答える 2

1

コンバーターを使用してすべての文字列を連結できます。必要なすべてのプロパティを含むオブジェクトインスタンスを渡す必要があります。

補足:StackPanelでfontsizeとforegroundをTextBlock.FontSizeとTextBlock.Foregroundとして設定できます。

于 2012-05-08T21:34:46.067 に答える
0

<Run>内の要素を使用できますTextBlock

<StackPanel Grid.Column="1" Orientation="Horizontal">
    <TextBlock FontSize="10" Foreground="#2C2C2C">
       <Run Text="Added by "  />
       <Run Text="{Binding Document.MEMUser.UserName}" />
       <Run Text=" on " />
       <Run Text="{Binding CreatedOn, Converter={StaticResource DateTimeToStringConverter}}" />
    </TextBlock>
    <!--BIND COMMANDS TO PARENT ViewModel to process operations-->
    <Button Content="Delete" Command="{Binding DataContext.DeleteCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
    <Button Content="Download" Command="{Binding DataContext.DownloadCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
</StackPanel>
于 2012-05-08T21:37:29.030 に答える