我试图在银灯上建立标识地位控制,在这种控制下,我将使用多个控制模板来界定有条件的内容。
至今,我已成立了洛辛斯塔图人委员会。
public class LoginStatusControl : ContentControl
{
// these are actually Depedency Properties
public ControlTemplate LoggedInTemplate { get; set; }
public ControlTemplate AnonymousTemplate { get; set; }
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var user = this.DataContext as User;
if (user == null && this.AnonymousTemplate != null)
{
this.Template = this.AnonymousTemplate;
}
else if (this.LoggedInTemplate != null)
{
this.Template = this.LoggedInTemplate;
}
}
}
然后,我以某种方式界定了模板。
<Style x:Key="UserStatusStyle" TargetType="local:LoginStatusControl">
<Setter Property="LoggedInTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="User " />
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding LastName}" />
<TextBlock Text=" is logged in" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="AnonymousTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="Please create your profile" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
很难找到与控制模板相连接的有条件模板。
在查询时,我发现,并试图使用具有约束力的模板,但我不得不这样做。
如果用户不作标记,是否有什么办法显示这种有条件的模板? 是否有另一种办法解决我失踪的问题? 我希望提出一个解决办法,以便在控制变化的数据内容发生变化时能够动态地更新模板。