markup-extensions

Accessing “current class” from WPF custom MarkupExtension

99封情书 提交于 2019-11-30 14:03:45
I'm attempting to write a custom MarkupExtension to make my life easier by giving me a better way to specify bindings in XAML. However I would like to know if there is any way I can access the object that represents the file the MarkupExtension is used in. In other words, suppose I have a UserControl that defines a particular rendition of a data model of my program. This control has lots of visual stuff like grids, borders and general layout. If I use my MarkupExtension on a particular property of some element in this UserControl , I want to access the instance of the UserControl , without

XAML markup binding to dictionary with key of type Type

随声附和 提交于 2019-11-30 13:34:35
问题 I'm trying to bind to a Dictionary<Type,string> through xaml. The problem is, the indexer [] in the Binding markup extension interprets it's content as string. Is there some kind of 'unescape-sequence' for that case? <TextBox Text="{Binding theDictionary[{x:Type ns:OnePrettyType}]}" /> (Binding doesn't work because {x:Type ns:OnePrettyType} is being sent as string) 回答1: If the indexer has a specific type the conversion should be done automatically so this should work: {Binding theDictionary

WPF - Getting a property value from a binding path

↘锁芯ラ 提交于 2019-11-30 08:31:49
if I have an object say called MyObject, which has a property called MyChild, which itself has a property called Name. How can I get the value of that Name property if all I have is a binding path (i.e. "MyChild.Name"), and a reference to MyObject? MyObject -MyChild -Name I found a way to do this, but it's quite ugly and probably not very fast... Basically, the idea is to create a binding with the given path and apply it to a property of a dependency object. That way, the binding does all the work of retrieving the value: public static class PropertyPathHelper { public static object GetValue

How to debug Visual Studio 2012 instance design-time

六月ゝ 毕业季﹏ 提交于 2019-11-30 08:31:47
I'm developing a WPF MarkupExtension and encountered errors during design time. With the previous version of Visual Studio 2010 it was possible to start a second instance of Visual Studio 2010 and attach to the process of the already-running instance, setting breakpoints and debugging the design time behavior. In Visual Studio 2012 however I can attach to the process of another Visual Studio 2012 as well, but no symbols are loaded in the second instance and therefor I'm not able to debug the design time as with Visual Studio 2010. How do I get this debugger running? Things I've tried: "devenv

XAML markup binding to dictionary with key of type Type

折月煮酒 提交于 2019-11-30 07:24:55
I'm trying to bind to a Dictionary<Type,string> through xaml. The problem is, the indexer [] in the Binding markup extension interprets it's content as string. Is there some kind of 'unescape-sequence' for that case? <TextBox Text="{Binding theDictionary[{x:Type ns:OnePrettyType}]}" /> (Binding doesn't work because {x:Type ns:OnePrettyType} is being sent as string) If the indexer has a specific type the conversion should be done automatically so this should work: {Binding theDictionary[ns:OnePrettyType]} If you need an explicit interpretation you can try a "cast" like this: {Binding

Accessing “current class” from WPF custom MarkupExtension

北慕城南 提交于 2019-11-29 19:30:00
问题 I'm attempting to write a custom MarkupExtension to make my life easier by giving me a better way to specify bindings in XAML. However I would like to know if there is any way I can access the object that represents the file the MarkupExtension is used in. In other words, suppose I have a UserControl that defines a particular rendition of a data model of my program. This control has lots of visual stuff like grids, borders and general layout. If I use my MarkupExtension on a particular

How to debug Visual Studio 2012 instance design-time

女生的网名这么多〃 提交于 2019-11-29 12:35:01
问题 I'm developing a WPF MarkupExtension and encountered errors during design time. With the previous version of Visual Studio 2010 it was possible to start a second instance of Visual Studio 2010 and attach to the process of the already-running instance, setting breakpoints and debugging the design time behavior. In Visual Studio 2012 however I can attach to the process of another Visual Studio 2012 as well, but no symbols are loaded in the second instance and therefor I'm not able to debug the

WPF - Getting a property value from a binding path

梦想的初衷 提交于 2019-11-29 11:52:06
问题 if I have an object say called MyObject, which has a property called MyChild, which itself has a property called Name. How can I get the value of that Name property if all I have is a binding path (i.e. "MyChild.Name"), and a reference to MyObject? MyObject -MyChild -Name 回答1: I found a way to do this, but it's quite ugly and probably not very fast... Basically, the idea is to create a binding with the given path and apply it to a property of a dependency object. That way, the binding does

Improved IValueConverter — MarkupExtension or DependencyObject?

非 Y 不嫁゛ 提交于 2019-11-28 19:41:32
I saw online 2 different approaches to enhancing an IValueConverter. One of them extended a ValueConverter from MarkupExtension, the other from DependencyObject. I can't extend from both, so I'm wondering if any one is better than the other? Deriving from each gives you different kind of power and flexibility: Deriving from MarkupExtension enables you to use the value converter without making it a static resource, as described below: public class DoubleMe : MarkupExtension, IValueConverter { public override object ProvideValue(IServiceProvider serviceProvider) { return this; } public object

MarkupExtension that uses a DataBinding value

隐身守侯 提交于 2019-11-28 07:02:55
I'm trying to create a WPF MarkupExtension class that provides translated text from my text translation class. The translation stuff works great, but requires a static method call with a text key to return the translated text. Like this: ImportLabel.Text = Translator.Translate("import files"); // will be "Dateien importieren" in de or "Import files" in en Its speciality is that it accepts a counting value to provide better wordings. ImportLabel.Text = Translator.Translate("import n files", FileCount); // will be "Import 7 files" or "Import 1 file" Another example: If something takes yet 4