markup-extensions

Default Constructor Parameter in MarkupExtension declaration

一笑奈何 提交于 2020-12-28 18:24:18
问题 Reducing this question to the bare minimum, consider this MarkupExtension class... public class ProblemStatement : MarkupExtension { private readonly string _first; private readonly string _second; public ProblemStatement(string first, string second) { _first = first; _second = second; } public override object ProvideValue(IServiceProvider serviceProvider) { return this; } public override string ToString() { return _first + _second; } } When this Xaml is declared... <Grid> <TextBlock Name=

MarkupExtension is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types

限于喜欢 提交于 2020-05-31 05:25:31
问题 I have a custom markup extensions "ThemeExtension" to provide "SolidColorBrush" from my DefaultTheme.xaml ResourceDictionary. Calling example: BorderBrush="{extensions:Theme Key= FooKeyValue}" It is working without any problems on runtime, but SOMETIMES it starting to crash during design time and I can't develop anymore. The designer is crashed. Rebuild, Clean Solution, OS Restart is NOT helping anymore. If I change some value inside of the XAML code it is working for exactly for 1 drawing!

Is there any way to instantiate a 'Type' in Silverlight XAML?

。_饼干妹妹 提交于 2020-01-05 10:10:13
问题 It's well known that Silverlight lacks the very compelling x:Type MarkupExtension (MarkupExtension is not supported in Silverlight at all). Is there any dynamic workaround for it? What about enums (x:Static)? My need is to have a CommandParameter set to a Type or Enum value, neither of these are supported in Silverlight! 回答1: This generally has to be done in the code-behind. Even if you build a custom object that exposes a property of type Type, it will not get properly "converted" when set

x:Type and arrays--how?

家住魔仙堡 提交于 2019-12-25 06:22:27
问题 Long story short, I need to do this: ExpressionType="{x:Type sys:Byte[]}" In other words, I need to do this: foo.ExpressionType=typeof(byte[]); Wat do? Update: Its a bug in the 2010 design surface. It works fine at runtime. 回答1: If there is no way to do it in the framework, then you can write your own markup extension: public class ArrayTypeExtension : MarkupExtension { public ArrayTypeExtension() {} public ArrayTypeExtension(Type type) { this.Type = type; } public Type Type { get; set; }

How to create a XAML markup extension that returns a collection

Deadly 提交于 2019-12-20 10:34:42
问题 I am using XAML serialization for an object graph (outside of WPF / Silverlight) and I am trying to create a custom markup extension that will allow a collection property to be populated using references to selected members of a collection defined elsewhere in XAML. Here's a simplified XAML snippet that demonstrates what I aim to achieve: <myClass.Languages> <LanguagesCollection> <Language x:Name="English" /> <Language x:Name="French" /> <Language x:Name="Italian" /> </LanguagesCollection> <

Markup Extension in Data Trigger

本秂侑毒 提交于 2019-12-10 16:38:03
问题 To translate my WPF application I use a Markup extension which returns a Binding object. This allows me to switch the language while the application is running. I use this Markup like this: <TextBlock Text="{t:Translate 'My String'}" />" I would like to change a Buttons text through a data Trigger: <Button> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <!-- Custom control template, note the TextBlock formating --> <ControlTemplate TargetType="

Custom MarkupExtension in UWP

无人久伴 提交于 2019-12-10 16:07:42
问题 I would like to create my own MarkupExtension (like Binding , TemplateBinding ...) How can I do it for Universal Apps like I did in WPF? 回答1: I has a sad, but no. UWP doesn't currently support custom markup extensions. In some cases you can work around this by using bindings and converters. For example, to use a resource string (not using x:Uid ), I have a converter that doesn't actually need a value, only a parameter (the resource id). For example, I might bind as follows: <TextBlock Text="

How to make Resharper resolve path for CustomBinding MarkupExtension

拈花ヽ惹草 提交于 2019-12-09 04:59:16
问题 I want to create some extended Binding-Markup-Extension, which behaves just like a normal WPF-Binding but does some things more (use different defaults, maybe add some behavior, etc.). Code looks like this: public class CustomBindingExtension : Binding { .. some extra properties and maybe overrides ... } It all works fine including XAML-intellisense, except I just can't make Resharper resolve my Binding-Path correctly. I.e.: using this code I can [Strg]+Click on 'CurrentText' and Resharper

IValueConverter with MarkupExtension

孤街浪徒 提交于 2019-12-08 22:00:36
问题 Recently I read about an IValueConverter which also inherits from MarkupExtension . It was something like: internal class BoolToVisibilityConverter : MarkupExtension, IValueConverter { private static BoolToVisibilityConverter converter; public BoolToVisibilityConverter() { } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is bool) { if ((bool)value) { return Visibility.Visible; } } return Visibility.Collapsed; } public object ConvertBack

Dynamic enum converter

女生的网名这么多〃 提交于 2019-12-08 12:25:17
问题 I want to create a dynamic 2-way-converter for all possible enums in my application. I don't want to have to create a converter for each enum, I want to create one converter that provides converting from enum to byte and from byte to enum vice versa. How can I get there? My approach is already 2-way but requires a static cast (MyEnum) in the code: public class MyEnumConverter : MarkupExtension, IValueConverter { public object Convert(object value, System.Type targetType, object parameter,