How to concatenate button contents in xaml?

I tried to combine two lines as Button content in XAML. But that does not work. I tried as below:

 <Button Content=""String1"+{DynamicResource String2}"/> 
+7
source share
5 answers

use the concept of multi-connectivity. This It will help you well.

+2
source

The code in XAML is as follows:

  <Button> <TextBlock> <Run Text="String1"/> <Run Text="{DynamicResource String2}"/> </TextBlock> </Button> 
+5
source

You can use MultiBinding with the StringFormat parameter:

 <Button> <MultiBinding StringFormat="{}{0}{1}"> <Binding> <Binding.Source> <sys:String> String1 </sys:String> </Binding.Source> </Binding> <Binding Path="{DynamicResource String2}" /> </MultiBinding> </Button> 
+2
source

A simple, but not incredibly scalable way to handle this:

 <Window x:Class="AdHocWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <System:String x:Key="String2">String2</System:String> </Window.Resources> <Grid> <Button> <TextBlock> <System:String>String1 </System:String> <TextBlock Text="{DynamicResource String2}"/> </TextBlock> </Button> </Grid> </Window> 

TextBlocks are mostly small streaming documents, so they are very flexible.

+1
source

How to associate content with a value in a model or presentation model, and then you can set it much easier than you want dynamically and have much more control over it. Of course you will have to use MVVM ..

however, 2kay answer is better ...

0
source

All Articles