xaml

Apply stroke to a textblock in WPF

How do you apply stroke (outline around text) to a textblock in xaml in WPF? ...

How do you bind in xaml to a dynamic xpath?

I have a list box that displays items based on an xpath. This xpath changes depending on user selection elsewhere in the gui. The xpath always refers to the same document. At the moment i use some c# code behind to change the binding of the control to a new xpath expression. I'd like instead to bind in xaml to an xpath and then change...

How do you troubleshoot WPF UI problems?

I'm working on a WPF application that sometimes exhibits odd problems and appears to hang in the UI. It is inconsistent, it happens in different pages, but it happens often enough that it is a big problem. I should mention that it is not a true hang as described below. My first thought was that the animations of some buttons was the p...

How do I stop Blend 2.5 June Preview replacing Canvas.ZIndex with Panel.ZIndex on SL1.0 XAML?

I have a Silverlight 1.0 application that I edit with Blend 2.5. Whenever I touch a UIElement in the designer that has a Canvas attribute such as Canvas.ZIndex="1", when it updates the XAML, it changes the Canvas prefix to Panel, leaving Panel.ZIndex="1", causing the page to fail to load. How do I make it stop the insanity!?! I have u...

databinding a property to either of two dependency properties

I have two custom controls that are analogous to a node and the control that draws links between nodes. I would like to have both controls written as much in xaml as possible. The link stores both nodes as dependency properties, and I use databinding to move the line between the nodes whenever the nodes move. It would be great to be...

How does a XAML definition get turned into an object instance?

XAML allows you to specify an attribute value using a string that contains curly braces. Here is an example that creates a Binding instance and assigns it to the Text property of the TextBox element. <TextBox Text="{Binding ElementName=Foo, Path=Bar}"/> I want to extend XAML so that the developer could enter this as valid... <TextBox...

WPF and string formatting

Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key="whatever" Text="foo\nbar" /> </Window.Resources> Obviously I want a newline character in the MyClass.Text property, but the XAML parser constructs the object with the literal string "foo\nbar". Is there (a) a way to convince the parser to translate escape sequ...

Immutable Styles in Silverlight 2

Anyone found a good pattern for getting around immutable styles in Silverlight 2? What I mean is does anyone have a workaround for the fact that you cannot switch the style of an element programmatically once it has been set, i.e. the second line here will throw a catastrophic failure exception: this.TestButton.Style = (Style)Applicatio...

Convert an image to XAML?

Does anyone know of any way to convert a simple gif to xaml? E.G. A tool that would look at an image and create elipses, rectangles and paths based upon a gif / jpg / bitmap? ...

On a WPF ComboBox, is it possible to set a different Foreground color for the textbox and the popup?

Basically my problem stems from a desire to have the textbox portion be white, and the drop down to be black. When I set the text to white, the drop down appears as I want it, but the text in the textbox itself is hardly readable. Setting the Foreground to black makes the drop down unreadable. Is there a good way to handle this? I am st...

Databinding 2 WPF ComboBoxes to 1 source without being "linked"

I have a master-detail scenario where I have 1 ComboBox listing companies from an ObjectDataSourceProvider. Under that I have 2 ComboBoxes binding to the Contacts property from the current Company object. I need to be able to select a different contact in each ComboBox; however, as soon as I change selection in one list the other list ...

Is this a crazy way to handle multi Validation types with IDataError and WPF?

Hi We are using the standard method for our controls to report broken BO rules. This is done via the interface IDataError in our BO’s and in XAML the control is bound to the BO’s property etc. This approach works OK. But we need to show 2 types of visuals in the UI depending on the type (or category if you like) of the invalidation erro...

Creating a XAML Resource from Code Without a Key

Is there a way to add a resource to a ResourceDictionary from code without giving it a resource key? For instance, I have this resource in XAML: <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type xbap:FieldPropertyInfo}" ItemsSource="{Binding Path=Value.Values}"> <TextBlock Text="{Binding Path=Name...

How to bind from a ContentTemplate to the surrounding custom Control?

I've got the following user control: <TabItem x:Name="Self" x:Class="App.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" > <TabItem.Header> <!-- This works --> <TextBlock Text="{B...

How do I share a menu definition between a context menu and a regular menu in WPF

I have a defined MenuItem that I would like to share between two different menus on one page. The menu contains functionallity that is the same between both menus and I do not want two copies of it. Is there anyway to define a MenuItem in the Page.Resources and reference it in the ContextMenu XAML below? <Page.Resources> <MenuItem x...

WPF Commands and Parameters

I'm finding the WPF command parameters to be a limitation. Perhaps that's a sign that I'm using them for the wrong purpose, but I'm still giving it a try before I scrap and take a different tack. I put together a system for executing commands asynchronously, but it's hard to use anything that requires data input. I know one common pat...

Storyboards cant find ControlTemplate elments.

I've created some fairly simple XAML, and it works perfectly (at least in KAXML). The storyboards run perfectly when called from within the XAML, but when I try to access them from outside I get the error: 'buttonGlow' name cannot be found in the name scope of 'System.Windows.Controls.Button'. I am loading the XAML with a stream read...

Dependence on DependencyObject and DependencyProperty

I'm building a Silverlight application and one of my caveats from last time was that if you need anything done right in Silverlight/WPF way you'd need to model your objects as a DependecyObject and use DependencyProperty(ies) I find this model to be rather cumbersome, requiring static fields and initializers in half the classes I use, ...

Setting Focus on a Control within a ControlTemplate in WPF

In an application I'm working on, we have a bunch of custom controls with their ControlTemplates defined in Generic.xaml. For instance, our custom textbox would look similar to this: <Style TargetType="{x:Type controls:FieldTextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Ty...

What are the limitations of Loose XAML?

I have been experimenting with WPF and rendering strict XAML markup in a web browser, also known as Loose XAML (explained here and here). It strikes me as mostly useful for displaying static content. However, it also appears possible to bind to an XML data provider. Loose XAML files are not compiled with an application, which create...