WPF: Style TextBlock, DataTrigger TextBlock . , ( ) WinRT. , IValueConverter, . , , .
, , , , , . , , , , ContentTable:
public class ContentTable
{
public string ItemTitle { get; set; }
public string ItemType { get; set; }
}
ItemTitle ItemType, type XML.
, , ItemTitle:
var data = from query in loadedData.Descendants("item")
select new ContentTable
{
ItemTitle = query.Element("title").Value,
ItemType = query.Attribute("type").Value
};
TextBlock (, FontWeight Margin), , string type TextBlock:
class ItemTypeToBoldConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
string text = value as string;
if (text != null)
{
return text == "Module" ?
Windows.UI.Text.FontWeights.Bold :
Windows.UI.Text.FontWeights.Normal;
}
return Windows.UI.Xaml.DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
class ItemTypeToMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
string text = value as string;
if (text != null)
{
return text == "Unit" ?
new Windows.UI.Xaml.Thickness(20, 0, 0, 0) :
new Windows.UI.Xaml.Thickness();
}
return Windows.UI.Xaml.DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
, .:)
(, DataTemplate):
<Page.Resources>
<local:ItemTypeToBoldConverter x:Key="itemTypeToBoldConverter1"/>
<local:ItemTypeToMarginConverter x:Key="itemTypeToMarginConverter1"/>
</Page.Resources>
, :
<DataTemplate>
<StackPanel Margin="10" >
<TextBlock Text="{Binding ItemTitle}"
FontWeight="{Binding ItemType, Converter={StaticResource itemTypeToBoldConverter1}}"
Margin="{Binding ItemType, Converter={StaticResource itemTypeToMarginConverter1}}"/>
</StackPanel>
</DataTemplate>
, FontWeight Margin, , ItemType. , . ItemType Module, ; . , ItemType Unit, ( 20); 0.
, XML XAML UI. HTML, <b>, <bold> <strong>. , . HTML. , XAML. , HTML-, .
, IMHO XSL, XML HTML-, XsltTransform ( , WinRT & hellip; ). WebView ( WPF, WebBrowser) HTML.