Search Results

Search found 238 results on 10 pages for 'controltemplate'.

Page 7/10 | < Previous Page | 3 4 5 6 7 8 9 10  | Next Page >

  • using style in WPF

    - by Polaris
    In my application I use ShinyBlue.xaml resourse Dictionary which has this code for GroupBox control: <Style TargetType="{x:Type GroupBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupBox}"> <Grid SnapsToDevicePixels="true"> <Grid.ColumnDefinitions> <ColumnDefinition Width="6" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="6" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="6" /> </Grid.RowDefinitions> <Border Grid.ColumnSpan="4" Grid.RowSpan="4" Background="{DynamicResource LightBrush}" CornerRadius="4,4,4,4" BorderThickness="1,1,1,1" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> These style common for all app. But in one of the forms I want to change background to Transparent. I want override only Background Property but it's not work <Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}"> <Setter Property="Background" Value="Transparent"/> </Style> code above not works properly How can I change GroupBox Background in specific form ?.

    Read the article

  • WPF : Multiple views, one DataContext

    - by zapho
    Hi, I'm working on a WPF application which must handle multiple screens (two at this this time). One view can be opened on several screens and user actions must be reflected consistently on all screens. To achieve this, for a given type of view, a single DataContext is instantiated. Then, when a view is displayed on a screen, the unique DataContext is attached to it. So, one DataContext, several views (same type of view/xaml). So far so good. It works quite well in most cases. I do have a problem with a specific view which relies on ItemsControl. These ItemsControl are used to display UIElements dynamically build in the ViewModel/DataContext (C# code). These UIElements are mostly Path objects. Example : <ItemsControl ItemsSource="{Binding WindVectors}"> <ItemsControl.Template> <ControlTemplate TargetType="{x:Type ItemsControl}"> <Canvas IsItemsHost="True" /> </ControlTemplate> </ItemsControl.Template> </ItemsControl> Here, WindVectors is a ObservableCollection<UIElement>. When the view is opened the first time, everything is fine. The problem is that when the view is opened one another screen, all ItemsControl are removed from the first screen and displayed one the second screen. Other WPF components (TextBlock for instance) on this view react normally and are displayed on both screens. Any help would be greatly appreciated. Thanks. Fabrice

    Read the article

  • How do you align text so it is in the middle of a button in Silverlight?

    - by Roy
    Here is the current code I am using: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ButtonPrototype.MainPage" Width="640" Height="480"> <UserControl.Resources> <ControlTemplate x:Key="CellTemplate" TargetType="Button"> <Grid> <Border x:Name="CellBorderBrush" BorderBrush="Black" BorderThickness="1"> <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </Grid> </ControlTemplate> <Style x:Key="CellStyle" TargetType="Button"> <Setter Property="Template" Value="{StaticResource CellTemplate}"></Setter> <Setter Property="Foreground" Value="Black"></Setter> <Setter Property="FontSize" Value="80"></Setter> <Setter Property="Width" Value="100"></Setter> <Setter Property="Height" Value="100"></Setter> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Button Content="A" Style="{StaticResource CellStyle}"></Button> </Grid> </UserControl> The Horizontal aligning works but the verticalalignment doesn't do anything. Thanks for your help.

    Read the article

  • Issue binding Image Source dependency property

    - by Archana R
    Hello, I have created a custom control for ImageButton as <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Local:ImageButton}"> <StackPanel Height="Auto" Orientation="Horizontal"> <Image Margin="0,0,3,0" Source="{Binding ImageSource}" /> <TextBlock Text="{TemplateBinding Content}" /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> ImageButton class looks like public class ImageButton : Button { public ImageButton() : base() { } public ImageSource ImageSource { get { return base.GetValue(ImageSourceProperty) as ImageSource; } set { base.SetValue(ImageSourceProperty, value); } } public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(ImageButton)); } However I'm not able to bind the ImageSource to the image as: (This code is in UI Folder and image is in Resource folder) <Local:ImageButton x:Name="buttonBrowse1" Width="100" Margin="10,0,10,0" Content="Browse ..." ImageSource="../Resources/BrowseFolder.bmp"/> But if i take a simple image it gets displayed if same source is specified. Can anyone tell me what shall be done?

    Read the article

  • Using a Control Template for all controls across the application

    - by samar
    Hi, I have a control template in one of my pages and i am assigning this template to my textbox's Validation.ErrorTemplate property. The following code would give you a better view. <ControlTemplate x:Key="ValidationErrorTemplate"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <AdornedElementPlaceholder/> <Image Name="ValidizorImage" Stretch="None" Source="validizor.gif" ToolTip="{Binding [0].ErrorContent}" ToolTipService.InitialShowDelay="0" ToolTipService.ShowDuration="60000"/> </StackPanel> </ControlTemplate> The above template sets the image at the end of the textbox which is having the error. This template is used as below. <TextBox Grid.Column="5" Grid.Row="1" x:Name="txtemail" Grid.ColumnSpan="3" Margin="0,1,20,1" Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}" /> My question here is I want to move this control template outside of this page so that i can use it across the application. I tried putting the exact same code of the control template in a user control say "ErrorUC" and using it as below TextBox1.SetResourceReference (System.Windows.Controls.Validation.ErrorTemplateProperty, new ErrorUC()); On running the above code i learnt that "AdornedElementPlaceholder" can be used only in templates and not in user controls. If i comment the same i am not getting the desired result. Can anyone please help! Thanks in advance! Regards, Samar

    Read the article

  • Silverlight MVVM Confusion: Updating Image Based on State

    - by senfo
    I'm developing a Silverlight application and I'm trying to stick to the MVVM principals, but I'm running into some problems changing the source of an image based on the state of a property in the ViewModel. For all intents and purposes, you can think of the functionality I'm implementing as a play/pause button for an audio app. When in the "Play" mode, IsActive is true in the ViewModel and the "Pause.png" image on the button should be displayed. When paused, IsActive is false in the ViewModel and "Play.png" is displayed on the button. Naturally, there are two additional images to handle when the mouse hovers over the button. I thought I could use a Style Trigger, but apparently they're not supported in Silverlight. I've been reviewing a forum post with a question similar to mine where it's suggested to use the VisualStateManager. While this might help with changing the image for hover/normal states, the part missing (or I'm not understanding) is how this would work with a state set via the view model. The post seems to apply only to events rather than properties of the view model. Having said that, I also haven't successfully completed the normal/hover affects, either. Below is my Silverlight 4 XAML. It should also probably be noted I'm working with MVVM Light. <UserControl x:Class="Foo.Bar.MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="200"> <UserControl.Resources> <Style x:Key="MyButtonStyle" TargetType="Button"> <Setter Property="IsEnabled" Value="true"/> <Setter Property="IsTabStop" Value="true"/> <Setter Property="Background" Value="#FFA9A9A9"/> <Setter Property="Foreground" Value="#FF000000"/> <Setter Property="MinWidth" Value="5"/> <Setter Property="MinHeight" Value="5"/> <Setter Property="Margin" Value="0"/> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Image Source="/Foo.Bar;component/Resources/Icons/Bar/Play.png"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="Active"> <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" Storyboard.TargetName="/Foo.Bar;component/Resources/Icons/Bar/Play_Hover.png" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Image> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Button Style="{StaticResource MyButtonStyle}" Command="{Binding ChangeStatus}" Height="30" Width="30" /> </Grid> </UserControl> What is the proper way to update images on buttons with the state determined by the view model? Update I changed my Button to a ToggleButton hoping I could use the Checked state to differentiate between play/pause. I practically have it, but I ran into one additional problem. I need to account for two states at the same time. For example, Checked Normal/Hover and Unchecked Normal/Hover. Following is my updated XAML: <UserControl x:Class="Foo.Bar.MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="200"> <UserControl.Resources> <Style x:Key="MyButtonStyle" TargetType="ToggleButton"> <Setter Property="IsEnabled" Value="true"/> <Setter Property="IsTabStop" Value="true"/> <Setter Property="Background" Value="#FFA9A9A9"/> <Setter Property="Foreground" Value="#FF000000"/> <Setter Property="MinWidth" Value="5"/> <Setter Property="MinHeight" Value="5"/> <Setter Property="Margin" Value="0"/> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ToggleButton"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Pause"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Collapsed</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="MouseOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PlayHover"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Play"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Collapsed</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="CheckStates"> <VisualState x:Name="Checked"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Pause"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Play"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Collapsed</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PlayHover"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Collapsed</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Unchecked" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Image x:Name="Play" Source="/Foo.Bar;component/Resources/Icons/Bar/Play.png" /> <Image x:Name="Pause" Source="/Foo.Bar;component/Resources/Icons/Bar/Pause.png" Visibility="Collapsed" /> <Image x:Name="PlayHover" Source="/Foo.Bar;component/Resources/Icons/Bar/Play_Hover.png" Visibility="Collapsed" /> <Image x:Name="PauseHover" Source="/Foo.Bar;component/Resources/Icons/Bar/Pause_Hover.png" Visibility="Collapsed" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <ToggleButton Style="{StaticResource MyButtonStyle}" IsChecked="{Binding IsPlaying}" Command="{Binding ChangeStatus}" Height="30" Width="30" /> </Grid> </UserControl>

    Read the article

  • Set button content in a label (custom control)

    - by user1881207
    Instead of voting negative this question, answer to tell me what's wrong! I want to set the Button Content in a label in the custom control, because when I use it, the Content property is not visible and the button is empty (no text). <Button x:Class="WpfApplication1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="35" d:DesignWidth="273" Content="Button"> <Button.Template> <ControlTemplate> <Grid> <Rectangle Name="rGridBack" StrokeThickness="1"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4D4D4D" Offset="1" /> <GradientStop Color="#FF404040" Offset="0" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.Stroke> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4F4F4F" Offset="0" /> <GradientStop Color="#FF5B5B5B" Offset="1" /> </LinearGradientBrush> </Rectangle.Stroke> </Rectangle> <Rectangle Fill="#FF1E1E1E" Margin="1,1,1,1" Name="rThickness" /> <Rectangle Margin="2,2,2,2" Name="rGridTop" StrokeThickness="1"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF68686C" Offset="0" /> <GradientStop Color="#FF474747" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.Stroke> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF7F7F7F" Offset="0" /> <GradientStop Color="#FF575757" Offset="1" /> </LinearGradientBrush> </Rectangle.Stroke> </Rectangle> <!--This label is where I want to set the Button.Content property--> <Label FontWeight="Normal" Foreground="White" HorizontalContentAlignment="Center" Name="tblckStep1Desc" Padding="0" VerticalContentAlignment="Center"> <Label.Effect> <DropShadowEffect BlurRadius="2" Color="Black" Direction="330" Opacity="0.7" ShadowDepth="1.5" /> </Label.Effect> </Label> </Grid> <ControlTemplate.Triggers> <Trigger Property="Button.Content" Value=""> <Setter Property="Content" TargetName="tblckStep1Desc"> </Setter> </Trigger> <Trigger Property="UIElement.IsMouseOver" Value="True"> <Setter Property="Shape.Fill" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF838383" Offset="0" /> <GradientStop Color="#FF545454" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF595959" Offset="1" /> <GradientStop Color="#FF929292" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridBack"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF414141" Offset="0" /> <GradientStop Color="#FF565656" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Fill" TargetName="rThickness"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF181818" Offset="1" /> <GradientStop Color="#FF181818" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter Property="Shape.Fill" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF68686C" Offset="0" /> <GradientStop Color="#FF474747" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF7F7F7F" Offset="0" /> <GradientStop Color="#FF575757" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridBack"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4F4F4F" Offset="0" /> <GradientStop Color="#FF5B5B5B" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Fill" TargetName="rThickness"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF1E1E1E" Offset="1" /> <GradientStop Color="#FF1E1E1E" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Control.Foreground" TargetName="tblckStep1Desc"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF898989" Offset="1" /> <GradientStop Color="#FF898989" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="ButtonBase.IsPressed" Value="True"> <Setter Property="Shape.Fill" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF313131" Offset="1" /> <GradientStop Color="#FF2E2E2E" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridTop"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF1F1F1F" Offset="1" /> <GradientStop Color="#FF1F1F1F" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Stroke" TargetName="rGridBack"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF414141" Offset="1" /> <GradientStop Color="#FF565656" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Shape.Fill" TargetName="rThickness"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF0C0C0C" Offset="1" /> <GradientStop Color="#FF0C0C0C" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> The button is based on Adobe CS5 suite on dialog forms, because a lot of code.

    Read the article

  • How can I bind Wpf DataGridColumn to an object?

    - by John
    I want to bind the columns of my WPF DataGrid to some objects in a Dictionary like this: Binding Path=Objects[i] where Objects is my Dictionary of objects, so that each cell will represent an Object element. How can I do that? I suppose that I need to create a template for my cell, which I did, but how to get the result of column binding in my template? I know that by default the content of a DataGridCell is a TextBlock and it's Text property is set through column binding result, but if that result is an object I guess that I have to create a ContentTemplate. How do I do that, as the stuff I tried is not displaying anything. Here it is what I tried: <Style x:Key="CellStyle" TargetType="{x:Type dg:DataGridCell}"> <Setter Property="Template"> ---it should realy be ContentTemplate? <Setter.Value> <ControlTemplate> <controls:DataGridCellControl CurrentObject="{Binding }"/> -- I would expect to get the object like this for this column path : Path=Objects[i] but is not working </ControlTemplate> </Setter.Value> </Setter> </Style> So, to make myself completly clear, i want to get in CurrentObject property of my DataGridCellControl the current object that should result if I set the column binding in my data grid like this Path=Objects[i]. Thank you for any suggestion, John.

    Read the article

  • What shall be the code in xaml which makes a particular image to act as a button?

    - by Abhi
    Dear all I am new to Silverlight. And i have to make a demo application where in designing is done by using Microsoft Expression Blend 2 and developing should be done using Visual Studio(c++). Now i am first trying to become familiar with xaml files. So i was trying to make a simple demo where in i have to create a button and that button should be replace with an png image. In order to do so i tried with the mentioned below example. But i was not able to see anything in the screen. <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SilverlightApplication1.Page" Width="640" Height="480"> <Grid x:Name="LayoutRoot" Background="White"> <Button x:Name="LogoutButton" > <Button.Template> <ControlTemplate> <Image Source="SilverlightApplication1\bounce_photo.png" /> </ControlTemplate> </Button.Template> </Button> </Grid> Please let me know where i am wrong and what shall i do to obtain the result. With regards Abhineet Agarwal

    Read the article

  • Group panel of WPF ListBox

    - by rulestein
    I have a listbox that is grouping the items with a GroupStyle. I would like add a control at the bottom of the stackpanel that holds all of the groups. This additional control needs to be part of the scrolling content so that the user would scroll to the bottom of the list to see the control. If I were using a listbox without the groups, this task would be easy by modifying the ListBox template. However, with the items grouped, the ListBox template seems to only apply on a per group basis. I can modify the GroupStyle.Panel, but that doesn't allow me to add items to that panel. <ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.GroupStyle> <GroupStyle> <GroupStyle.Panel> <ItemsPanelTemplate> <VirtualizingStackPanel/> **<----- I would like to add a control to this stackpanel** </ItemsPanelTemplate> </GroupStyle.Panel> <GroupStyle.ContainerStyle> <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <Grid> <ItemsPresenter /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </ListBox.GroupStyle> This should give an idea of what I need to do:

    Read the article

  • Windows Phone 8 Panorama SelectionIndex not changing on swiping through items

    - by Balraj Singh
    I have created Panorama control and binded PanoramaItem from ItemSource. Now when i am changing the selected Panoramaitem by swiping over them the Selected index is always set to -1. I dont know what wrong i am doing while implementation. neither selectionchange event is getting fired. Code: <phone:Panorama Grid.Row="1" Visibility="Visible" x:Name="PnrVwMainNews" ItemsSource="{Binding ParnormaItemsData}" ItemContainerStyle="{StaticResource PanoramaContainerItemStyle}"> <phone:Panorama.ItemTemplate> <DataTemplate> <!-- Panorma Items Template --> <Controls:DynamicContentControl Content="{Binding UsrCntrlDynamic}" /> </DataTemplate> </phone:Panorama.ItemTemplate> </phone:Panorama> PanoramaContainerItemStyle <Style x:Key="PanoramaContainerItemStyle" TargetType="phone:PanoramaItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="VerticalContentAlignment" Value="Stretch" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="phone:PanoramaItem"> <Grid Background="{TemplateBinding Background}" Margin="12,0,0,0"> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Grid.Row="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

    Read the article

  • How to display combo box as textbox in WPF via a style template trigger?

    - by Greg R
    I would like to display a combobox drop down list as a textbox when it's set to be read only. For some reason I can't seem to bind the text of the selected item in the combo box to the textbox. This is my XAML: <Style x:Key="EditableDropDown" TargetType="ComboBox"> <Style.Triggers> <Trigger Property="IsReadOnly" Value="True"> <Setter Property="Background" Value="#FFFFFF" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <TextBox Text="{TemplateBinding SelectedItem, Converter={StaticResource StringCaseConverter}}" BorderThickness="0" Background="Transparent" FontSize="{TemplateBinding FontSize}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" FontFamily="{TemplateBinding FontFamily}" Width="{TemplateBinding Width}" TextWrapping="Wrap"/> </ControlTemplate> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> <ComboBox IsReadOnly="{Binding ReadOnlyMode}" Style="{StaticResource EditableDropDown}" Margin="0 0 10 0"> <ComboBoxItem IsSelected="True">Test</ComboBoxItem> </ComboBox> When I do this, I get the following as the text: System.Windows.Controls.ComboBoxItem: Test I would really appreciate the help!

    Read the article

  • WPF: Binding an integer to a TextBlock with TemplateBinding

    - by haagel
    I have a custom control in WPF. In this I have a DependencyProperty of the type integer. In the template for the custom control I have a TextBlock, I and would like to show the value of the integer in the TextBlock. But I can't get it to work. I'm using TemplateBinding. If I use the same code but change the type of the DependencyProperty to string it works fine. But I really want it to be an integer for the rest of my application to work. How can I do this? I've written simplified code that shows the problem. First the custom control: public class MyCustomControl : Control { static MyCustomControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomControl), new FrameworkPropertyMetadata(typeof(MyCustomControl))); MyIntegerProperty = DependencyProperty.Register("MyInteger", typeof(int), typeof(MyCustomControl), new FrameworkPropertyMetadata(0)); } public int MyInteger { get { return (int)GetValue(MyCustomControl.MyIntegerProperty); } set { SetValue(MyCustomControl.MyIntegerProperty, value); } } public static readonly DependencyProperty MyIntegerProperty; } And this is my default template: <Style TargetType="{x:Type local:MyCustomControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:MyCustomControl}"> <Border BorderThickness="1" CornerRadius="4" BorderBrush="Black" Background="Azure"> <StackPanel Orientation="Vertical"> <TextBlock Text="{TemplateBinding MyInteger}" HorizontalAlignment="Center" /> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> What am I doing wrong? Thanks // David

    Read the article

  • WPF ListView Button - Associate multiple images

    - by Narayanan
    I have a listview in a WPF application that has a button in one of its columns. I associate a image to the button control. I want to configure different images for this button based on the How do I write the XAML in this scenario??? This is what I have already: <ControlTemplate x:Key="IconButtonAddProfile" TargetType="{x:Type Button}"> <Grid> <Image x:Name="myimage" Source="rofile.png" Height="27" Width="65" /> <Border> <ContentPresenter Content="{TemplateBinding Content}"/> </Border> </Grid> </ControlTemplate> <ListView.View> <GridView> <GridViewColumn Header="Security" Width="50"> <GridViewColumn.CellTemplate> <DataTemplate> <Button Template="{StaticResource IconButtonLockSecure}" DataContext="{Binding}" MinHeight="20" MinWidth="50" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </ListView.View>

    Read the article

  • How can i change background image of a button when hover or click in XAML for Windows 8?

    - by apero
    I got a question about changing the background image of a button when it's clicked. I tried searching on google but i couldn't find something that worked for me. Well here's my code <Button Grid.Column="0" Grid.Row="0" x:Name="btnHome" VerticalAlignment="Stretch" BorderBrush="{x:Null}" HorizontalAlignment="Stretch" Click="btnHome_Click" PointerEntered="btnHome_PointerEntered"> <Button.Template> <ControlTemplate TargetType="Button"> <Border x:Name="RootElement"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="MouseOver"> <Storyboard> //I want my background change here </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> //And here </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border.Background> <ImageBrush ImageSource="images/back_button.png"/> </Border.Background> </Border> </ControlTemplate> </Button.Template> </Button> i also tried this private void btnHome_PointerEntered(object sender, PointerRoutedEventArgs e) { BitmapImage bmp = new BitmapImage(); Uri u = new Uri("ms-appx:images/back_button_mouseover.png", UriKind.RelativeOrAbsolute); bmp.UriSource = u; ImageBrush i = new ImageBrush(); i.ImageSource = bmp; btnHome.Background = i; } But unfortunately this worked neither

    Read the article

  • WPF DataGridRow Template - how to achieve Selected event

    - by user1809972
    I would like to override the DataGridRow template depending on the datatype of object bound to the grid. If the type is label, it just shows a Label. Otehrwise, it shows the cells. Follwing is the xaml. <DataTrigger Binding="{Binding Path=IsLabel, UpdateSourceTrigger=PropertyChanged}" Value="True"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridRow}"> <Grid> <Label HorizontalAlignment="Center" Padding="3,3,3,3" FontWeight="Bold" Content="{Binding Id}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> The grid looks ok. But, when the Label is clicked, it doesnt raise the Selection changed event for the DataGridRow. How do I achieve this behaviour? This label should just behave as any other DataGridRow(with the default template). Thanks

    Read the article

  • Column Header Styling Issue in Data Grid in WPF

    - by sbrakl
    I have formated the Wcf Toolkit Datagrid and below in the is the ColumnHeader Style for it But, there are still some area in Column Header, which are not styled as shown in the image http://www.freeimagehosting.net/uploads/9aba4fbd93.jpg <Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}"> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Background" Value="Orange" /> <Setter Property="Foreground" Value="White" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="dg:DataGridColumnHeader"> <dg:DataGridHeaderBorder x:Name="headerBorder" Background="Orange"> <Border BorderThickness="2" CornerRadius="5" Background="Orange" BorderBrush="DarkOrange"> <Grid> <TextBlock Text="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap"/> </Grid> </Border> </dg:DataGridHeaderBorder> </ControlTemplate> </Setter.Value> </Setter> </Style> <dg:DataGrid Grid.Row="1" Grid.RowSpan="1" Name="dgQuestion" HorizontalAlignment="Left" AutoGenerateColumns="True" Width="740" MinWidth="200" MaxWidth="740" Background="Wheat" ColumnHeaderHeight="30" ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" RowStyle="{StaticResource RowStyle}" CanUserAddRows="False" CanUserDeleteRows="False" AlternationCount="2"/>

    Read the article

  • How can I show grouping in a WPF Data Grid with multiple levels?

    - by Keith
    I am relatively new to WPF, so I understand about Styles and setters, but I am having trouble on this one. I am using a WPF Data Grid and need to show multiple levels of grouping. I would like the 2nd and 3rd group levels to be more indented than the top level. The following code will show group levels, but it shows them one right on top of the other and makes the fact that they are nested group levels impossible to tell. <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <Expander IsExpanded="True"> <Expander.Header> <TextBlock Text="{Binding Path=Name}"/> </Expander.Header> <ItemsPresenter /> </Expander> </ControlTemplate> </Setter.Value> </Setter> </Style> How can I get the group header to indent based on level?

    Read the article

  • Is there a Visual Studio (or freeware) equivalent for Expression Blend's "Edit Template" feature?

    - by DanM
    In Expression Blend, you can view and edit the control template of objects in the "Objects and Timeline" panel. I'm wondering if there's an equivalent feature in Visual Studio or if there's something free (or very inexpensive) I can download that will allow me to do this. Here's a screen cap from Expression Blend that shows what I'm talking about: Doing this for DataGrid results in the following: <Style x:Key="DataGridStyle1" TargetType="{x:Type Custom:DataGrid}"> ... <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Custom:DataGrid}"> ... </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsGrouping" Value="True"> <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> </Trigger> </Style.Triggers> </Style> (The ... is of course replaced with setters and the contents of the control template.) This is a very useful starting point if you want to create a custom style and template for a control. It seems like you can do pretty much anything you can do in Blend in Studio, but this one is eluding me. Any ideas? Edit I'm also curious if this feature will be in Visual Studio 2010. Anyone know?

    Read the article

  • Custom progress bar label text via binding

    - by Alexander K
    I was playing with progress bar customization in Silverlight application. What I want to reach is to have progress bar label to show current its state in the following format: "Value / Maximum". So, user will see what is the current value, and what is the maximum possible value. Here is a style for progress bar I use: <Style x:Key="ProgressBarStyle" TargetType="ProgressBar"> <Setter Property="Width" Value="97.21" /> <Setter Property="Height" Value="19" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ProgressBar"> <Canvas x:Name="LevelField" Width="99" Height="21"> ... <TextBlock ... DataContext="{TemplateBinding Value}" Text="{Binding Converter={StaticResource DecNumberToStringConverter}}"/> </Canvas> </ControlTemplate> </Setter.Value> </Setter> </Style> The way I want to implement this, is to have a value converter, that will convert current value and maximum possible into the proper string. It does work properly, if it is written like above. However, I also need to provide ConverterParameter for Convertor, but not sure how to make it. When I write like this: , ConvertParameter={Binding Maximum}, it shows error on start, that Text attribute is not found in TextBlock. I was also trying to set DataContext as {RelativeSource Self}, but then it didn't displays error that DataContext attribute is not found. How to make the described progress bar label properly?

    Read the article

  • WPF DataGrid binding to UserControl

    - by Trindaz
    I have a DataGrid with one column using a UserControl via a styled DataGridTemplateColumn. I can't seem to get the UserControl to 'see' the object that is in it's containing DataGridCell though. What kind of bindings can I create on the TextBox in my UserControl so that it can look up and see that object?! My UserControl and TemplateColumn Style are defined as: <Window.Resources> <local:UCTest x:Key="UCTest" /> <Style x:Key="TestStyle" TargetType="{x:Type WpfToolkit:DataGridCell}"> <Style.Setters> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type WpfToolkit:DataGridCell}"> <Grid Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource drc}, Path=DataContext}"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <local:UCTest /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style.Setters> </Style> </Window.Resources> and my sample DataGrid is defined as: <WpfToolkit:DataGrid Name="dgSampleData" ItemsSource="{Binding}" AutoGenerateColumns="True" Margin="0,75,0,0"> <WpfToolkit:DataGrid.Columns> <WpfToolkit:DataGridTemplateColumn Header="Col2" CellStyle="{StaticResource TestStyle}" /> </WpfToolkit:DataGrid.Columns> </WpfToolkit:DataGrid> and my User Control is defined in a separate file as: <UserControl x:Class="UCTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="clr-namespace:WpfApplication1" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="104" Height="51"> <UserControl.Resources> <local:DataRowConverter x:Key="drc" /> </UserControl.Resources> <Grid> <TextBox Margin="12,12,-155,16" Name="TextBox1" Text="" /> </Grid> EDIT: My implementation of TestClass, which has the Test Property, which I want UCTest.TextBox1 to bind do: Public Class TestClass Private _Test As String = "Hello World Property!" Public Property Test() As String Get Return _Test End Get Set(ByVal value As String) _Test = value End Set End Property End Class Thanks in advance!

    Read the article

  • Wrap or adorn wpf listview datatemplate

    - by Chris Cap
    I'm attempting to essentially wrap the contents of a DateTemplate in a listview gridview column with a border. What I want to know is if it's possible to supply an adorner that will surround that template so that I don't have to specify the border in every single datatemplate on every column (which is what I'm doing now). I've got something like this, but I know it's not right <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="TemplateContent"> <Setter.Value> <ControlTemplate> <StackPanel> <Border BorderBrush="Green" BorderThickness="1"> <AdornedElementPlaceholder /> </Border> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> This complains that Templatecontent is not a valid type. I've also tried with DataTemplate and that doesn't work either (understandably so). I know I could just create a DataTemplate, however the content for each column is different. At the very least, it binds to different fields. I'm wondering if there's a solution using a dynamic resource, but I don't know much about it. Thanks for your help EDIT: here's a sample of my listview <ListView ItemsSource="{Binding Path=OrderLines}" ItemContainerStyle="{StaticResource ResourceKey=ListViewItemContainerStyle}"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox MaxWidth="30" Width="30" MaxLength="2" Text="{Binding Path=Quantity,ValidatesOnDataErrors=True}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridView> <ListView.View> </ListView> Essentially I want to wrap that text box in the data template and any other items in additional columns.

    Read the article

  • WPF Memory Leak

    - by Oskar Kjellin
    I have an WPF form that I myself did not create, so I am not very good at WPF. It is leaking badly though, up to 400 MB and closing the form does not help. The problem lies in my application loading all the pictures at once. I would like to only load the ones visible at the moment. It is about 300 pictures and they are a bit large so my WPF-form suffers from loading them all. I have a DataTemplate with my own type that has a property Thumbnail. The code in the template is like this: <Image Source="{Binding Path=Thumbnail}" Stretch="Fill"/> And then I have a grid with a control that has the above template as source. The code for this control is the below. Please provide me with hints on how to optimize the code and perhaps get the only ones that are visible and only have that many controls loaded at the same time? <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Controls:ElementFlow"> <Grid Background="{TemplateBinding Background}"> <Canvas x:Name="PART_HiddenPanel" IsItemsHost="True" Visibility="Hidden" /> <Viewport3D x:Name="PART_Viewport"> <!-- Camera --> <Viewport3D.Camera> <PerspectiveCamera FieldOfView="60" Position="0,1,4" LookDirection="0,-1,-4" UpDirection="0,1,0" /> </Viewport3D.Camera> <ContainerUIElement3D x:Name="PART_ModelContainer" /> <ModelVisual3D> <ModelVisual3D.Content> <AmbientLight Color="White" /> </ModelVisual3D.Content> </ModelVisual3D> <Viewport2DVisual3D RenderOptions.CachingHint="Cache" RenderOptions.CacheInvalidationThresholdMaximum="2" RenderOptions.CacheInvalidationThresholdMinimum="0.5"/> </Viewport3D> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

    Read the article

  • MapItemsControls not updating Silverlight Bing Map

    - by Matt
    I'm using a MapItemsControl to control my Pushpin items within my Bing silverlight map. Right on the page load, I add a new pin programatically, and the pin shows up on the map. However I've now taken it further and I'm adding pins to my datasource via a click on the map. The new pins add to my datasource, but do not show up on the map. Do I need to rebind my datasource to my map control or somehow refresh the datasource? Here's some code <UserControl.Resources> <DataTemplate x:Key="PinData"> <m:Pushpin Location="{Binding Location}" PositionOrigin="BottomCenter" Width="Auto" Height="Auto" Cursor="Hand"> <m:Pushpin.Template> <ControlTemplate> <Grid> <myTestApp:MasterPin DataContext="{Binding}"/> </Grid> </ControlTemplate> </m:Pushpin.Template> </m:Pushpin> </DataTemplate> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <m:Map x:Name="myMap" CredentialsProvider="" Mode="Road" ScaleVisibility="Collapsed" > <m:MapItemsControl x:Name="mapItems" ItemTemplate="{StaticResource PinData}"/> </m:Map> </Grid> public partial class Map : UserControl { private List< BasePin > dataSource = new List< BasePin >(); public Map() { InitializeComponent(); _Initialize(); } private void _Initialize() { //this part works and adds a pin to the map dataSource.Add( new BaseSite( -33.881532, 18.440208 ) ); myMap.MouseClick += Map_MouseClick; mapItems.ItemsSource = dataSource; } public void Map_MouseClick(object sender, MapMouseEventArgs e)) { BasePin pin = new BasePin(); pin.Location = myMap.ViewportPointToLocation( e.ViewportPoint ); dataSource.Add( pin ); } }

    Read the article

  • Create a grid in WPF as Template programmatically

    - by wickie79
    I want to create a basic user control with a style programmatically. In this style i want to add a Grid (no problem), but i dont can add column definitions to this grid. My example code is ControlTemplate templ = new ControlTemplate(); FrameworkElementFactory mainPanel = new FrameworkElementFactory(typeof(DockPanel)); mainPanel.SetValue(DockPanel.LastChildFillProperty, true); FrameworkElementFactory headerPanel = new FrameworkElementFactory(typeof(StackPanel)); headerPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); headerPanel.SetValue(DockPanel.DockProperty, Dock.Top); mainPanel.AppendChild(headerPanel); FrameworkElementFactory headerImg = new FrameworkElementFactory(typeof(Image)); headerImg.SetValue(Image.MarginProperty, new Thickness(5)); headerImg.SetValue(Image.HeightProperty, 32d); headerImg.SetBinding(Image.SourceProperty, new Binding("ElementImage") { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent) }); headerPanel.AppendChild(headerImg); FrameworkElementFactory headerTitle = new FrameworkElementFactory(typeof(TextBlock)); headerTitle.SetValue(TextBlock.FontSizeProperty, 16d); headerTitle.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); headerTitle.SetBinding(TextBlock.TextProperty, new Binding("Title") { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent) }); headerPanel.AppendChild(headerTitle); FrameworkElementFactory mainGrid = new FrameworkElementFactory(typeof(Grid)); FrameworkElementFactory c1 = new FrameworkElementFactory(typeof(ColumnDefinition)); c1.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star)); FrameworkElementFactory c2 = new FrameworkElementFactory(typeof(ColumnDefinition)); c2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Auto)); FrameworkElementFactory c3 = new FrameworkElementFactory(typeof(ColumnDefinition)); c3.SetValue(ColumnDefinition.WidthProperty, new GridLength(3, GridUnitType.Star)); FrameworkElementFactory colDefinitions = new FrameworkElementFactory(typeof(ColumnDefinitionCollection)); colDefinitions.AppendChild(c1); colDefinitions.AppendChild(c2); colDefinitions.AppendChild(c3); mainGrid.AppendChild(colDefinitions); mainPanel.AppendChild(mainGrid); FrameworkElementFactory content = new FrameworkElementFactory(typeof(ContentPresenter)); content.SetBinding(ContentPresenter.ContentProperty, new Binding() { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), Path = new PropertyPath("Content") }); mainGrid.AppendChild(content); templ.VisualTree = mainPanel; Style mainStyle = new Style(); mainStyle.Setters.Add(new Setter(UserControl.TemplateProperty, templ)); this.Style = mainStyle; But the creation of FrameworkElementFactory with type ColumnDefinitionCollection will throw an exception "'ColumnDefinitionCollection' type must derive from FrameworkElement, FrameworkContentElement, or Visual3D." Who can help me?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10  | Next Page >