xaml

WPF: XAML property declarations not being set via Setters?

I have a WPF application where I'm using dependency properties in codebehind which I want to set via XAML declarations. e.g. <l:SelectControl StateType="A" Text="Hello"/> So in this example I have a UserControl called SelectControl, which has a property called StateType which manipulate some other properties in it's setter. To help...

How to rewrite the same XAML DataBinding in Code

How do I recreate the following XAML databinding in code? I have most of it except for the DataTemplate definition. Here is an example of the DataBinding in XAML <GridViewColumn Width="140" Header="Name"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=Label}" /> ...

Binding to Self/'this' in XAML

Hi. Simple WPF/XAML question. In XAML, how do I reference the Self/this object in a given context? In a very basic app with a main window, one control, and a coded C# property of the window, I want to bind a property of the control to the hand coded property of the window. In code, this is very easy - in the Window's constructor, I add...

Equivalent XAML line to this C#

Hi. In a WPF app, what XAML code do I need to do the same job as this line of c#: this.DataContext = this; ? Thanks ...

Text content in a WPF button not being centred vertically

Is there a reason why the text content of a WPF button is appearing with unwanted space above the text? I have a button in a StackPanel. This button is a simple close button so I want it to appear as a square button with an "x" centred in it. I have set my padding to zero and set both the HorizontalContentAlign and VerticalContentAlig...

Instantiate and reuse instances of objects in XAML

I want to instantiate objects in XAML, and reuse these instances. I think it should be simple but I'm stuck, I'm probably missing something obvious. Say I want to add Cats to different Rooms (Room has an ObservableCollection containing objects of type Cat). In the UserControl.Resources I create ObjectDataProviders: <ObjectDataProvider ...

Passing a value along from a Button in a WPF ListView

I have a collection that I am displaying in a WPF Listview. I will have an edit button in each row and need to pass an ID to another control on the screen when that's clicked. I'm not going to be editing in place so I'm not using the Gridview. How do I pass this ID to my other control? Currently my XAML looks like this. <ListView Na...

Is it possible to dynamically choose which Control to render based on bindable attribute in Silverlight 4?

I have a ListBox with an ItemTemplate which renders a Grid with two columns. The first column is a TextBlock and the second is a ComboBox. The idea is to present to the user a list of questions and a Combo from which the user can choose an answer. This works ok with this xaml: <ListBox x:Name="QAListBox" ScrollViewer.VerticalS...

How do I add a 'checked'/'unchecked' event handler to a checkbox in codebehind using Silverlight?

Okay this one's pretty straightforward. I'm creating a checkbox in my Page.xaml.cs file, and assigning it some params. I need to link to events for checked and unchecked. What is the syntax for this? Also, my current code looks like this: CheckBox cb = new CheckBox(); cb.IsChecked = true; System.Windows.Thicknes...

XamlObjectWriter throws exception while writing from XamlXmlReader - .Net 4

For some reason I get an exception. Can someone please explain to me why and how can fix this? I am trying to read a DataTemplate. If there is a better option please tell. Thanks. using System; using System.Windows; using System.Windows.Data; using System.IO; using System.Xaml; using System.Xml; namespace TestApp { public partial c...

Can I insert a Window into another Window?

I have two Window (name: window1 \ window2) whether it is possible to insert them in another Window (window3). What would have once been seen window1 \ window2, buyout lie window3? ...

How select Text in TextBock?

I only found a way to: <TextBox Text="Text!" IsReadOnly="True" IsTabStop="False" BorderThickness="0" > <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Va...

Prompt tool for Visual Studio 2010 to package xaml code

I need a tool for rapid code generation from <DockPanel DockPanel.Dock="Top"><TextBlock Text=" " /><TextBox Style="{StaticResource TextBoxIsReadOnly}" Text="{Binding title}" Foreground="Chocolate" DockPanel.Dock="Left"/></DockPanel> in: <DockPanel DockPanel.Dock="Top"> <TextBlock Text=": " /> <TextBox Style="{StaticResource ...

Silverlight: Controls looking different in Visual Studio v. debugging

I have a text box that appears in a certain size and position in the Visual Studio Silverlight preview window. When I actually run the app, it appears to be much wider, and lower on the page. Why is this? (Sometimes I can fix the problem by deleting the control and making a new one like it, but it's frustrating.) This is the XAML: <Tex...

Layout in silverlight

I am running into a layout issue which I am not sure how to solve. Here is how my xaml looks like, <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid x:Name="abc" Grid.Row="0" Grid.Column="0"> <Grid> <Grid.ColumnDe...

binding a textbox on gridfrom

I have a datagrid which is populated from a web service. I want to fill a form based on the selected item in the datagrid. This is what I use to set the DataContext (Which is a grid) private void PublisherSearchList_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.PublisherItem.DataContext = (Publisher)Publis...

How to add comment for an attribute definition from within a tag?

Let's say we have the below code: <Window x:Class="Consus.Client.UI.Sandbox.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" x:Name="Ribbo...

WPF Localization in XAML, what is the simple, easy and elegant way of doing it?

I have a very common question. What is the best way to do localization in a WPF app. Well, I searched in SO and Binged a lot too. But I could not find any pointers which is really simple and elegant. Assume that I have to display in UI something like: In English: Orgnanization - Beoing In French: Organizzazione - Beoing <St...

WPF DataGrid customization: alignment, scrolling, performance, usability

I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity Framework as connection tool between database and application. In one of the windows there is need to show content of database's table and let user to perform some manipulations, such as add new record to database, edit selected record and ...

Silverlight XAML: Binding to property in EntityClass from assosiated EntityCollection (advanced?!)

This question relates to this question. I have a EF model like this. Using Silverlight 4 I have an application showing questions to the user, defined through the QuestionSet. If a question has more than one answer alternative, a ComboBox is rendered. If only one alternative is given, a TextBox is rendered, in which the user can put fre...