本文整理汇总了C#中System.Windows.Controls.ContentPresenter.CacheLanguage方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPresenter.CacheLanguage方法的具体用法?C# ContentPresenter.CacheLanguage怎么用?C# ContentPresenter.CacheLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentPresenter
的用法示例。
在下文中一共展示了ContentPresenter.CacheLanguage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoDefaultExpansion
private void DoDefaultExpansion(TextBlock textBlock, object content, ContentPresenter container)
{
Debug.Assert(!(content is String) && !(content is UIElement)); // these are handled by different templates
Inline inline;
if ((inline = content as Inline) != null)
{
textBlock.Inlines.Add(inline);
}
else
{
bool succeeded = false;
string stringFormat;
XmlLanguage language = container.Language;
System.Globalization.CultureInfo culture = language.GetSpecificCulture();
container.CacheLanguage(language);
if ((stringFormat = container.ContentStringFormat) != null)
{
try
{
stringFormat = Helper.GetEffectiveStringFormat(stringFormat);
textBlock.Text = String.Format(culture, stringFormat, content);
succeeded = true;
}
catch (FormatException)
{
}
}
if (!succeeded)
{
TypeConverter tc = TypeDescriptor.GetConverter(ReflectionHelper.GetReflectionType(content));
TypeContext context = new TypeContext(content);
if (tc != null && (tc.CanConvertTo(context, typeof(String))))
{
textBlock.Text = (string)tc.ConvertTo(context, culture, content, typeof(string));
}
else
{
Debug.Assert(!(tc != null && tc.CanConvertTo(typeof(UIElement)))); // this is handled by a different template
textBlock.Text = String.Format(culture, "{0}", content);
}
}
}
}