xaml

How to style a label with a colon

I have a details view window in WPF and a label may look like this. <Label Content="{x:Static properties:Resources.Reference}" /> So that is obtains it content from my property Resource. How can transform/format the content so it has a colon after each label item. e.g. instead of the content simply displaying Reference I want it t...

Is there an MVVM-friendly way to swap views without value converters firing unnecessarily?

I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing ...

How to set a binding in WPF Toolkit Datagrid's ContextMenu CommandParameter

I need to create a ContextMenu where I want to pass a currently selected index of the datagrid to a ViewModel using CommandParameter. The following Xaml code doesn't work. What might be the problem? <dg:DataGrid ItemsSource="{Binding MarketsRows}" <dg:DataGrid.ContextMenu > <ContextMenu > <MenuItem Header="Add Di...

[WPF] ComboBox.Text not taking the ItemStringFormat property into account

I just noticed a strange behavior which looks like a bug. Consider the following XAML : <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <Page.Resources> <x:Array x:Key="data" Type="{x:Type sys:St...

ReSharper: 'Name' attribute is not allowed here; use 'x:Name' instead in XAML

ReSharper's complaining about some of my XAML with the following error: 'Name' attribute is not allowed here because type 'FlashingTextBlock' is implemented in the same project. Use 'x:Name' instead What's the problem here? Should I do what it says? ...

Declare a Nullable int (int?) using XAML

I am trying to bind a combo box to a property on my ViewModel. The target type is short? and I would like to have null be an option. Basically I would like the value of the first item in the combo box be {x:Null}. <ComboBox Grid.Row="9" Grid.Column="1" SelectedValue="{Binding Priority}"> <clr:Int16></clr:Int16> ...

WPF Formatting Issues - Automatically stretching and resizing?

I'm very new to WPF and XAML. I am trying to design a basic data entry form. I have used a stack panel holding four more stack panels to get the layout I want. Perhaps a grid would be better for this, I am not sure. Here is an image of my form in action: http://yfrog.com/7gscreenshot1impp And here is the XAML code that generates it:...

OneWay binding throws "TwoWay binding is invalid on Read only property"

This binding <tk:DataGridTextColumn Binding="{Binding Path=Id, Mode=OneWay}" Header="Sale No." Width="1*" /> Gives this error A TwoWay or OneWayToSource binding cannot work on the read-only property 'Id' of type . . . The "Id" property is indeed readonly, I thought though that Mode=OneWay would be sufficient. I'm tired and...

WPF List of ViewModels bound to list of Model objects.

In the model, I have: public ObservableCollection<Item> Items { get; private set; } In the ViewModel, I have a corresponding list of ItemViewModels. I would like this list to be two-way bound to the model's list: public ObservableCollection<ItemViewModel> ItemViewModels ... In the XAML, I will bind (in this case a TreeView) to the...

WPF Trigger / Style overrides another

I have a listview defined as such <ListView Width="auto" SelectionMode="Single" ItemContainerStyle="{StaticResource ItemContStyle}" .... Then in "baseListViewStyle" I have defined some base styles to apply to my lis...

Styling WPF Toolkit DataGrid Column Headers

Hi, I'm having an issue styling the WPF Datagrid, I've styled the column headers (of type ColumnHeader). But when the data in the columns does not fill the full width of the grid an additional column is added to pad out the grid. This column ignores the ColumnHeader style and looks out of place presumably because the element has a d...

Binding position to ActualHeight

Hi I want to bind a lists position to its own height in XAML. So its lower left corner always will be at 0.0 of the canvas. I'm using elementBinding to get the ActualHeight and a converter to invert the property. But the height sent to the converter is 0. How do I solve this or am I going at this the wrong way? <Canvas x:Name="DisplayS...

What is the easiest way to generate a Valid x:Name?

I am generating some Xaml based on some other source of input. In some cases I am generating x:Name values but they have invalid characters. I found this article on MSDN: XamlName Grammar Which describes the grammar of a x:Name tag but doesn't tell me how to actually apply this. Clearly there is some code to validate this name at runti...

Center a TextBox over the top of a ScrollViewer in WPF.

I have a MainView that contains a navigation bar which selects one of many XAML pages to be displayed in the page view pane. The MainView contains a ScrollViewer around the pages. This allows the pages to be whatever size they need to be and the MainView's ScrollViewer scrolls them. This all works great. On one of the pages, I need t...

How can I refer to a binding converter in another namespace in Silverlight XAML?

Since you apparently can't create a Silverlight DataTemplate in C#, I'm trying to create one in XAML. I have a converter that I need to refer to, that I have defined in C# in another namespace. I've tried doing this: <UserControl.Resources> <DataTemplate x:Key="PriceTemplate"> <TextBlock Text="{Binding Price, Convert...

XAML resources aren't loaded when calling from different project

I have a WPF project with some styles in XAML in Application.Resources. This works perfectly fine. But when I open a window from this project from another one (this one is a console application), the resources from XAML aren't loaded. When I first tried it, I got a XamlParseException on StaticResource calls in XAML, so I changed it to Dy...

WPF: Real time timeline control needed

I need to reflect progress of execution of numerous tasks in real time. I wondering is it any WPF\Silverlight control which do this. Here what I found, but this controls don't meet my needs: http://blogs.msdn.com/llobo/archive/2010/04/30/sl-timeline-control-for-sharepoint.aspx http://timeline.codeplex.com/ http://timelinecontrol.co...

Reference an internal class from a Windows Workflow Activity

I'm creating a custom Workflow activity for use within TFS2010. In the same assembly I have a XAML activity and a C# code activity. The XAML activity references the code activity. When the assembly is deployed to our clients, I only want them to be able to use the Workflow activity. The code activity is of little use by itself and woul...

Silverlight - use a ScrollViewer in a TextBox template

I'm trying to make a TextBox template and I need to include a ScrollViewer in the template - basically I want to add some content (like line numbers) that needs to scroll along with the normal text. The default template for the TextBox is like this: <Border x:Name="Border" BorderBrush="{TemplateBinding Border...

XAML ListBox Binding

I'm working on a GIS website in C# and Silverlight, and I'm trying to populate a ListBox based on map layers. The code works if I lump everything together in a single XAML file (where the Map is defined in the same file), but I am trying to separate things into separate classes, and the ListBox will not populate in the other class. XAM...