xaml

WPF: A TextBox that has an event that fires when the Enter Key is pressed

Instead of attaching a PreviewKeyUp event with each TextBox in my app and checking if the pressed key was an Enter key and then do an action, I decided to implement extended version of a TextBox that includes a DefaultAction event that fires when an Enter Key is pressed in a TextBox. What I did was basically create a new Class that ex...

Silverlight Toolkit Accordion in TreeView

I'm trying to get the SL Tookit (March 2009) Accordion control to populate the ItemTemplate of a TreeView control, but it doesn't render properly (just a 1x1 pixel square). Here's my XAML: <UserControl x:Class="SilverlightTest.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas....

Access DataContext in code-behind

Beware, this is a rather basic question (I think). I have a UserControl, called MyUserControl. I use it in a DataTemplate for my ListBox: <l:MyUserControl DataContext="Test" /> Now I want to access this DataContext in the code-behind of MyUserControl, and I expect DataContext to contain a string object with contents "Test". However, ...

Can I handle thrown exceptions in XAML?

In my XAML I get all customers by binding to a GetAll property: <ListBox ItemsSource="{Binding GetAll}" ItemTemplate="{StaticResource allCustomersDataTemplate}" Style="{StaticResource allCustomersListBox}"> </ListBox> The GetAll property is an observable collection in my view model, which calls the Model to get all collecti...

Best way to serialize a wpf element tree to Xaml?

What is the best way to serialize a wpf element tree to xaml so that I can get a design time representation? XamlWriter.Save is having serious limitations, and it can provide only the run-time representation Probably Microsoft don't want any one to build a customized xaml designer with out much effort :( ...

How to adjust padding in xaml label

How can I make the top and bottom padding smaller in the following label? As I see it, the bounding box in much bigger than it needs to be, but the padding is set to 0, so it cannot be any smaller. <Label Background="AliceBlue" Content="1800" FontSize="170" FontWeight="Bold" Foreground="Gray" Padding="0" /> ...

WPF - Is there a good reason that Setter.Value isn't a ContentProperty?

Every time I write out a setter whose Value property value isn't describable inline, I curse the fact that the API doesn't mark the Setter class with [ContentProperty("Value")], which would allow this: <Setter Property="BitmapEffect"> <Setter.Value> <OuterGlowBitmapEffect GlowColor="#AAC" Opacity="0.2" GlowSize="1.25" /> </Sette...

WPF doesn't honor Textbox.MinLines for Auto height calculation

I want to have a TextBox which Height grows as Iam entering lines of Text. I've set the Height property to "Auto", and so far the growing works. Now I want that the TextBox's Height should be at least 5 lines. Now I've set the MinLines property to "5" but if I start the app the TextBox's height is still one line. ...

Click-to-edit in Silverlight

Is there a way to make a "click-to-edit" control in silverlight? I've got some items that will be displayed in a treeview control, and I would like the labels to be editable directly in the treeview. Anyone know how to do this? ...

Exception when serializing WPF contols

I have an Application (an appointment manager) which lets the user create usercontrols in a stackpanel per button click and the user can enter data into the usercontrols. So far so good. I serialized the stackpanel with XamlWriter.Save(). But then when I try to load it again the next time the application starts with XamlReader.Load() I ...

How can I overridding a bound property with a DataTrigger

I've got the following XAML used to display detailed information about an item selected in a list view. I want the rectangle to show the standard info color behind the text except when the selected item represents an error message. The code below doesn't work as is and always shows the info color. It works great if I don't specify a Fill...

[WPF C#]Get UserControl or VisualTree in DataValidation of TextBlock

Hy, I have a validator set on the text property of a textblock. For a correct validation I would need the parent usercontrol of the textblock, but the only things I have in the validator are the value object (a string) and the culture (doesn't help either). Does anyone know a way to get certain usercontrols in a class/a method where I ...

How to keep datasource updated in all WPF user controls?

I have WPF application with one main window. In this window there are a series of buttons which form a menu and a space where user controls are loaded at runtime. However, if the user changes data (stored in XML file) in one user control and then switches to another user control, the user does not see the updated data in the new user c...

How to remove the left-hand blue line on custom selected styled Listbox items?

I found this code which replaces the default select style with a custom style for the select ListBoxItem in a ListBox. However, there is still a little blue line on the left from the default style which I can't remove with any padding or margin changes. How can I remove that blue line and completely determine the style of the selected L...

How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox?

I want to have the ListItems to extend with their orange background the full width of the Listbox. Currently they are only as wide as the FirstName + LastName. I've set every element I can to: HorizontalAlignment="Stretch". I want the background of the ListboxItems to expand as the user stretches the Listbox so I don't want to put in ...

Reuse path object in XAML

Hi all, I have a Path (a star figure): <Path x:Name="NiceStar" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.45...

Is it possible to change the background color of a disabled button in WPF?

I am trying to get the effect of "dimming out the whole window and all controls on it". The window and everything on it also needs to be disabled. The problem is that when button is disabled, it doesn't seem to let you change the Background color. Is there a way in WPF to change the background color of a button even though it is disa...

WPF: Display a bool value as "Yes" / "No"

I have a bool value that I need to display as "Yes" or "No" in a TextBlock. I am trying to do this with a StringFormat, but my StringFormat is ignored and the TextBlock displays "True" or "False". <TextBlock Text="{Binding Path=MyBoolValue, StringFormat='{}{0:Yes;;No}'}" /> Is there something wrong with my syntax, or is this type of ...

XSL Conversion XML->XML outputs only text?

Hi I have following XAML code which is the output from XamlWriter.Save(): <StackPanel Name="itemStack" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mm="clr-namespace:MindManager;assembly=MindManager"> <mm:Item Width="Auto" Height="Auto"> <Border BorderThickness="10,10,10,10" Name="border1" Height="Auto">...

How to share a numeric constant between xaml and c# in silverlight

I'm new to .NET programming, and trying to learn Silverlight 2 / C#. I need to declare numeric constants (or better yet, readonly variables), and access them in both XAML and my C# code-behind file. These values are more appropriately defined in XAML, but if the definition needs to be done in C#, that's better than hard-coding the val...