2017-01-24 64 views
0

我有一个DownloadModel其中包含两个属性。我想显示在一个单一的TextBlockUWP如何绑定到两个值?

<TextBlock Text="{x:Bind DownloadModel.Part1.Progress, Mode=OneWay}"/> 

这两个属性的总结有没有办法通过Download.Part1.ProgressDownload.Part2.Progress在一起,然后显示在TextBlock两者的总结?

(如果这是可能的Binding代替x:Bind,将被罚款过这样做) 感谢。

+0

通常这会用MultiBinding解决,但似乎并不存在于UWP中 – BradleyDotNET

+0

在MVVM模式中,您将创建在模型和视图之间转换的ViewModel。你的ViewModel会公开一个执行逻辑操作的公共属性Progress,并且该视图绑定到它。 –

+2

TextBlock可以在内容中分割为'Run'。使用两个“运行”并绑定每个人的“文本”属性。 – AVK

回答

3

你实际上可以在TextBlock内使用Run。您可以使用它像这样:

例如,我有这两个字符串:

private string FirstText = "This is the first text."; 
    private string SecondText = "This is the second text."; 

我在XAML有这样的:

<TextBlock Foreground="Black"> 
     <Run Text="{x:Bind FirstText}"/> 
     <Run Text="{x:Bind SecondText}"/> 
    </TextBlock> 

,这是应用程序的样子:

enter image description here

希望它有帮助!

+0

好点!但我实际上认为,如果你需要显示值,并且没有控制到这个,只需创建UserControl :) – khamitimur