【发布时间】:2015-03-11 12:50:18
【问题描述】:
我正在将一个 XML 文件反序列化为一个类,然后尝试在 ContentControl 中显示一些 XAML(存储在该类的一个属性中)。
这是我的 XML:
<CallSteps>
<CallStep>
<StepID>20</StepID>
<StepName>Intro</StepName>
<StepXaml>
<![CDATA[<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:uc="clr-namespace:CallTracker.Library.UserControls.BaseUserControls;assembly=CallTracker.Library">
<uc:LabelValueControl Label="TestLabel" Value="356733" />
</StackPanel>]]>
</StepXaml>
</CallStep>
<CallStep>
<StepID>30</StepID>
<StepName>Intro</StepName>
<StepXaml>
<![CDATA[<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:uc="clr-namespace:CallTracker.Library.UserControls.BaseUserControls;assembly=CallTracker.Library">
<uc:LabelValueControl Label="TestLabel2" Value="356738124315" />
</StackPanel>]]>
</StepXaml>
</CallStep>
</CallSteps>
这会正确反序列化为CallStep 对象的集合。以下是单个 CallStep 对象的样子:
作为我的代码的一部分,我有一个 CurrentCallStep,其中包含一个 CallStep。我想在ContentControl(或其他容器)中显示StepXaml中包含的XAML,使用类似:
在虚拟机中:
/// <summary>
/// Current call step object
/// </summary>
public CallStep CurrentCallStep
{
get { return _CurrentCallStep; }
set
{
_CurrentCallStep = value;
NotifyPropertyChanged(m => m.CurrentCallStep);
}
}
private CallStep _CurrentCallStep;
在视图中:
<!-- CurrentCallStep contains the XAML for the current call steps to be displayed -->
<ContentControl Content="{Binding CurrentCallStep.StepXaml}"
Background="LightBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
然而,这并没有将 XAML 转换为 XAML,而只是显示如下文本:
如何获取CurrentCallStep.StepXaml 中的文本以转换为 XAML?
【问题讨论】:
标签: c# wpf xaml contentcontrol