xaml

WPF: SelectedValue always null

In the following example SelectedValue of TabControl is always null. Why? <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"> <DockPanel> <TextBlock Text="{Binding SelectedValue, ElementName=Tabs}" DockPanel.Do...

Is there an XPath-like syntax in XAML that can get items out of a collection?

I have a Dictionary object in my ViewModel with key/values that translate words on the View. It is possible to get the language information as an XML object and then pick out the translated phrase with XPath, something like this: <TextBlock DataContext="{TranslatorDictionaryXml}" Text="{Binding XPath=/terms/term[key='edit']/value[@lang...

Path element of Siverlight issue

Hello everyone, Suppose I have the following XAML code, my confusions are, (1) I do not know the exact meaning of Data attribute, especially items starts with letter M/C, (2) there is no special configuration for TransformGroup (all using default settings), why put the TransformGroup here? <Path Height="2.75" Width="2.75" Data="M2.75...

Best ways to convert XPS to PDF (and vice-versa)?

I have XPS documents being generated from XAML User Controls that act as templates. I want to convert the XPS documents into alternative formats, mainly PDF, programmatically with a .NET based API. What is the best way to do this? ...

XAML or C# code-behind

I don't like to use XAML. I prefer to code everything in C#, but I think that I am doing things wrong. In which cases it is better to use XAML and when do you use C#? What is your experience? ...

How can I factor out a DataTemplate's binding in WPF?

I have a DataTemplate I want to reuse. The part I want to factor out is the binding, because it's the only thing that changes. My DataTemplate looks roughly like this. (There's actually quite a bit more to it, but I've taken out the extraneous stuff.) <DataTemplate> <TextBox Text="{Binding Name}" /> </DataTemplate> How can I reuse...

Why does DockPanel.Dock="Bottom" put element at the top?

The following code puts the two text elements at the top even though the second one is marked "Bottom". The background color goes all the way to the bottom so the DockPanel seems to stretch to the bottom. What am I not understanding about DockPanel? <Window x:Class="TestIndexer934.Views.MainView" xmlns="http://schemas.microsoft.com...

How can I make a XAML Slider element snap to allowed values only?

I have a slider with minimum value 0 and maximum value 1. When I currently slide it, the value gets set to a decimal value between 0 and 1, e.g. 0.2342343. However, I want the value to only be either 0 or 1 (so that my ViewModel property will register the change only if it is 0 or 1 and not multiple times as the user drags it from 0 to...

Why does WPF Binding update strings but not objects?

In the following code example, you can move the slider from German to English and see that text block get translated at runtime, however: only the TextBlock bound to a string gets updated the TextBlock bound to a Dictionary does not get updated It seems that the View simply gets the Dictionary object once and then doesn't update anym...

Using XAML vector graphics in WPF application

I have a vector image that I've defined in XAML. What is the proper way to use this resource in a WPF application? I want to have the vector image in its own XAML file, and then add the image to other UserControls in my application. What should be the top-level element in my XAML vector image? How do I refer to that image in other UserC...

Should your ViewModel expose XAML elements as properties or not?

Over at the StackOverflow question How can WPF Converters be used in an MVVM pattern? I've learned that Value Converters should not be used in the MVVM pattern since the functionality of a Value Converter should be handled by the ViewModel itself. This makes sense. But I remember reading that you should not expose XAML elements to the ...

SourceName with MultiTriggers

Is it possible to use a multiTrigger to evaluate properties on multiple elements? That don't reside within a template, but are within the Usercontrol/Window. Example: <CheckBox x:Name="checkBox1" /> <CheckBox x:Name="checkBox2" /> <CustomControl> <CustomControl.ContentTemplate> <DataTemplate> ...

Passing origin of ContextMenu into WPF Command

Interesting problem related to firing commands from context menu items... I want to fire a command to insert a row in my control, InsertRowCmd. This command needs to know where to insert the row. I could use Mouse.GetPosition(), but that would get me the position of the mouse currently, which would be over the menu item. I want to get...

When will there be support for WYSIWIG editing of Silverlight XAML in Visual Studio?

Why do we have to spend more $$$ for Expression Blend after I already spent $$$$ for Visual Studio 2008 with MSDN subscription? Will there be a service pack for 2008 to support this, will it be part of VS2010, or will we always have to use a separate tool? Thanks ...

Tools to convert html layouts to Silverlight 3.0

I have a couple of applications for clients that were dragged into the web kicking and screaming. I'd like to take a crack at moving some to Silverlight 3.0 if even just as a proof of concept exercise. I'd like to see if I could make them full apps, layout and all. I think the layout of the web app along w/ the graphics is good and do...

How can I get StackPanel to use an ItemTemplate?

In the following code, I tell the ComboBox to use the DataTemplate called CustomerTemplate by assigning its ItemTemplate attribute. StackPanel, however, doesn't have an ItemTemplate attribute. How can I get the StackPanel to also use CustomerTemplate? <Window.Resources> <DataTemplate x:Key="CustomerTemplate"> <StackPanel O...

How can I get a StackPanel to be only as wide as its content?

The following template shows dynamic information in a colored box. However, the box is always the full width of the DockPanel/screen. I could put a fixed Width in the Border element, but then a very long customer name might get cut off. How can I tell the Border that it should expand and contract its width based on width of its conten...

What is the correct syntax for using StringFormat with single binding?

I can get MultiBinding to work with StringFormat: <TextBlock.Text> <MultiBinding StringFormat="{}{0} {1} (hired on {2:MMM dd, yyyy})"> <Binding Path="FirstName"/> <Binding Path="LastName"/> <Binding Path="HireDate"/> </MultiBinding> </TextBlock.Text> But what is the correct syntax for single binding? Th...

Sizing customized button to size of content

Hi, I've created the following very simple button style: <ControlTemplate x:Key="SimpleButton" TargetType="{x:Type ButtonBase}"> <ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" /> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Propert...

How to get RadioButtons to work like ComboBox in MVVM pattern?

In the following code, the user selects a customer from the ComboBox and that customer's information is displayed in the box. Now I also want to get RadioButtons to work with the same functionality. I've got the RadioButtons to display the ObservableCollection of Customers, but how can I get the IsChecked to work, i.e. what is the equi...