markup-extensions

Markup Extensions in WPF/Silverlight

Has anyone ever created a custom markup extension in WPF or Silverlight? When would you ever want or need to do this? Any tips or sources on how to do it? ...

MarkupExtension as computed property in Template

Having such MarkupExtension public class Extension1 : MarkupExtension { private static int _counter = 0; public override object ProvideValue(IServiceProvider serviceProvider) { return string.Format("Item {0}", _counter++); } } and this XAML <ListBox> <ListBoxItem Content="{my:Extension1}"></ListBoxItem> <...

How do I resolve the value of a databinding?

I've made a markup extension for translating strings based on a key. Example <TextBlock Text="{Translate myKey}" /> Now I want to be able to use nested bindings for providing my keys. Example: <TextBlock Text="{Translate {Binding KeyFromDataContext}}" /> When I do this I get a System.Windows.Data.Binding object. By calling ProvideV...

How can I escape a single quote in a XAML markup extension property literal?

I have a value converter that formats numbers (I can't use SP1 yet unfortunately). It works fine until it gets a percentage. Here's an example: <TextBlock Text="{Binding Path=PercentageComplete, Converter={StaticResource NumberFormatter}, ConverterParameter='0.00 %'}" /> Unfortunat...

jQuery: A widget or plug-in to create text balloons

I need to create some balloons that will contain text messages, similar to what you would see on a BBS or a blog comments area. I am not looking for a tool-tips widget - There will be several per page and they will always be displayed. My requirements: Drop shadows, if possible, using images instead of the box-shadow style for compat...

x:Static markup extension

I have a Window.Resource object and the next statement <CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=someProperty}" x:Key="someView" /> But what if I need to point to a public property in the Window's code-behind, not the App's? I've tried to use 'this' instead of 'Applic...

Override default markup extensions

I have written custom markup extesions, but what if I need to override an markup extension already defined? For example, I need to serialize StaticResources references and not the values when using XamlWriter.Save(object obj) method, so I guess what I need is to write a custom markupextension inheriting from ‘StaticResourceExtension’ tha...

Get the value for a WPF binding

Ok, I didn't want a bunch of ICommands in my MVVM ViewModels so I decided to create a MarkupExtension for WPF that you feed it a string(the name of the method), and it gives you back an ICommand that executes the method. here's a snippet: public class MethodCall : MarkupExtension { public MethodCall(string methodName) { Method...

Accessing "current class" from WPF custom MarkupExtension

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 ...

'System.Windows.Data.MultiBinding' is not a valid value for property 'Text'.

I'm trying to write a custom MarkupExtension that allows me to use my own mechanisms for defining a binding, however when I attempt to return a MultiBinding from my MarkupExtension I get the above exception. I have: <TextBlock Text="{my:CustomMarkup ...}" /> CustomMarkup returns a MultiBinding, but apparently Text doesn't like being ...

The uncatchable exception

Followup: http://stackoverflow.com/questions/3057822/the-uncatchable-exception-pt-2 I'm writing a custom binding engine; my converter is being called before DataContext is set on the target element. This in and of itself isn't a big deal because it will get updated when DataContext eventually receives a value. What is causing problems i...

Question about this xaml markup extension

Hi, I'm trying to understand what does the markup extension for the x:Key attribute below do and what kind of markup extension is it? <Window x:Class="App1.Window1" xmlns:dxg="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt; <DataTemplate x:Key="{dxg:Example ResourceKey=Example}"> <dxg:TextEdit Text="123/> </DataTemp...

WPF - Custom Mark-up Extensions return RoutedEvents

Hello! I'm trying to create a generalized event for my Close buttons, where they have to close the window but before that set focus to the owner window. I don't want to have an event for every file for that, because that'd be pretty unpractical since I have 30+ windows in my application. (So if I wanted to change that behavior, i'd have ...

x:Type and arrays--how?

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. ...

How to reference a specific implementation of a generic type in the DataType attribute of a DataTemplate?

This question is strongly connected to this answer to "How to reference a generic type in the DataType attribute of a HierarchicalDataTemplate?" I followed the basic idea of that answer and created this data structure: <!-- for DictItemVM<string, Remote.Address> which is a viewmodel for a KeyValuePair<...> --> <x:Array Type="{x:Type sy...

WPF - Getting a property value from a binding path

Hi, 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 ...

How does IsSynchronizedWithCurrentItem really work with ContentControl and Data Templates?

I have a markup extension that is working with Binding. Things work well except when the markup extension is used in a DataTemplate which is then used by a ContentControl that is bound to the same property as a ListView with IsSynchronizedWithCurrentItem=true. How can I get the CurrentIt...

WPF - Unit testing a custom markup extension

Hi, how would you recommend unit testing a custom markup extension in WPF? Presumably, I need to create an instance of my markup extension and call the ProvideValue method. However, this requires an IServiceProvider, which contains an IProvideValueTarget service. How would I generate this programmatically? ...

Visual Studio 2010 and custom markup extension

Hello. I have created a custom MarkupExtension for localization like below: [System.Windows.Markup.MarkupExtensionReturnType(typeof(string))] [System.Windows.Markup.ContentProperty("LocalizedValue")] public class LocItem : System.Windows.Markup.MarkupExtension { public LocItem() :base() { } public string Localiz...