对于silverlight中的某个控件,根据不同的条件需要有不一样的样式,那么我们就需要用到StyleSelector.
如下:
public class ToggleRowDetailsStyle : StyleSelector
{
public Style Style1{ get; set; }
public Style Style2 { get; set; }
public override Style SelectStyle(object item, DependencyObject container)
{
if(...)
{
return Style1;
}
return Style2;
}
}
在页面中使用如下:
<local:ToggleRowDetailsStyle x:Key="ToggleRowDetailsStyle">
<local:ToggleRowDetailsStyle.Style1>
<Style TargetType="telerik:GridViewCell">
... </Style>
</local:ToggleRowDetailsStyle.Style1>
<local:ToggleRowDetailsStyle.Style2>
<Style TargetType="telerik:GridViewCell">
... </Style>
</local:ToggleRowDetailsStyle.Style2>
</local:ToggleRowDetailsStyle>