2012-05-08 13 views
0

我有這樣的XAML ..基本上它連接了多個綁定到不同屬性的字符串。比方說,出於某種原因,我不想在VM上公開另一個屬性,將它作爲單個屬性。在Silverlight和TextBlocks中綁定時string.format的種類?

是否有任何其他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> 

回答

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> 
+0

應該 – katit

+0

@katit:事實上,它應該,感謝您發現它。我現在編輯我的答案來糾正它。 –

1

你可以使用一個轉換器連接所有的字符串,你需要傳遞一些包含所有需要的屬性的對象實例。

旁註:你可以在StackPanel中作爲TextBlock.FontSize和TextBlock.Foreground

設置字體大小和前景