Search Results

Search found 159 results on 7 pages for 'relativesource'.

Page 5/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • WPF validation red border doesn't show If UserControl collapsed first

    - by Creepy Gnome
    There seems to be a bug with WPF in 3.5, and I was hoping someone may have found a workaround. Basically if you have a custom UserControl that contains a TextBox and it is in a Window but initialized to be Collapsed by default in the xaml or code behind if it fails validation when you make the control visible it will not show the red border until it fails while visible. However, this works correctly when visibility is set to Hidden, just no when Collapsed. I am already overriding the ErrorTemplate with a style to workaround the Adornment issue with the red border staying visibile when you collapse the control. Below is my full style for the TextBox. If there is any additional changes or additions to make it work correctly with collapsed controls that would be great. <Style TargetType="TextBox"> <Setter Property="Margin" Value="3" /> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <ControlTemplate.Resources> <BooleanToVisibilityConverter x:Key="converter" /> </ControlTemplate.Resources> <DockPanel LastChildFill="True"> <Border BorderThickness="2" BorderBrush="Red" Visibility="{ Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource converter}}" > <AdornedElementPlaceholder x:Name="placeholder" /> </Border> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true" > <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /> </Trigger> </Style.Triggers> </Style>

    Read the article

  • Set form MinWidth and MinHeight based on child property

    - by Jon Mitchell
    I'm writing an application in WPF using the MVVM pattern. In my application I've got an IPopupWindowService which I use to create a popup dialog window. So to show a ViewModel in a popup window you'd do something like this: var container = ServiceLocator.Current.GetInstance<IUnityContainer>(); var popupService = container.Resolve<IPopupWindowService>(); var myViewModel = container.Resolve<IMyViewModel>(); popupService.Show((ViewModelBase)myViewModel); This is all well and good. What I want to do is be able to set the MinHeight and MinWidth on the View bound to myViewModel and have the popup window use those settings so that a user cannot make the window smaller than its contents will allow. At the moment when the user shrinks the window the contents stops resizing but the window doesn't. EDIT: I map my Views to my ViewModels in ResourceDictionarys like so: <DataTemplate DataType="{x:Type ViewModels:MyViewModel}"> <Views:MyView /> </DataTemplate> And my popup view looks like this: <Window x:Class="TheCompany.Cubit.Shell.Views.PopupWindowView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterOwner"> <DockPanel x:Name="panelContent"> <StackPanel HorizontalAlignment="Right" DockPanel.Dock="Bottom" Orientation="Horizontal" Visibility="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=ButtonPanelVisibility}"> <Button Width="75" IsDefault="True" x:Uid="ViewDialog_AcceptButton" Click="OnAcceptButtonClick" Margin="4">OK</Button> <Button Width="75" IsCancel="True" x:Uid="ViewDialog_CancelButton" Click="OnCancelButtonClick" Margin="0,4,4,4">Cancel</Button> </StackPanel> <ContentPresenter Content="{Binding}" /> </DockPanel>

    Read the article

  • WPF - Centering a checkbox in a GridViewColumn?

    - by Sonny Boy
    Hey all, I'm currently struggling on getting my checkboxes to property center within my GridViewColumns. I've defined a style for my checkboxes like so: <Style TargetType="{x:Type CheckBox}" x:Key="DataGridCheckBox"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="IsEnabled" Value="False" /> <Setter Property="Margin" Value="4" /> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type GridViewColumn}},Path=ActualWidth}" /> </Style> And my checkboxes are added into the GridViewColumn using a DataTemplate like this: <GridViewColumn Header="Comment"> <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox Style="{StaticResource DataGridCheckBox}" IsChecked="{Binding PropertyItem.Comment, Converter={StaticResource booleanConverter}, ConverterParameter='string'}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> But the problem I have is that the checkboxes remain left-aligned (even when resizing the column). Any ideas? Thanks in advance, Sonny

    Read the article

  • Can't access resource from Generic.xaml within the Custom Control constructor.

    - by myermian
    I'm not sure why this is doing this, but I can't access the resource from within my constructor. XTabItem.cs using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace MyStuff { public class XTabItem : TabItem { public static readonly DependencyProperty XTabItemNormalBackgroundProperty; /// <summary> /// Visual Property: Normal Background /// </summary> [Description("Determines the visibility of the close button."), Category("XTabItem Visual")] public Brush XTabItemNormalBackground { get { return (Brush)GetValue(XTabItemNormalBackgroundProperty); } set { SetValue(XTabItemNormalBackgroundProperty, value); } } static XTabItem() { DefaultStyleKeyProperty.OverrideMetadata(typeof(XTabItem), new FrameworkPropertyMetadata(typeof(XTabItem))); XTabItemNormalBackgroundProperty = DependencyProperty.Register("XTabItemNormalBackground", typeof(Brush), typeof(XTabItem), new UIPropertyMetadata(null)); } public XTabItem() { //XTabItemNormalBackground = (Brush)this.TryFindResource("XTabItemNormalBackgroundBrush"); //THIS DOES NOT WORK?? } public override void OnApplyTemplate() { base.OnApplyTemplate(); } } } Generic.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyStuff" xmlns:con="clr-namespace:MyStuff.Converters" > <SolidColorBrush x:Key="XTabItemNormalBackgroundBrush" Color="BlueViolet" /> <Style TargetType="{x:Type local:XTabItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:XTabItem}"> <!-- CONTENT TEMPLATE --> <Grid SnapsToDevicePixels="True"> <Border x:Name="_Border" Background="{Binding Path=XTabItemNormalBackground, RelativeSource={RelativeSource Mode=TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,1,0"> ... </Border> </Grid> </Style> </ResourceDictionary>

    Read the article

  • lighten background color on button click per binding

    - by one of two
    I want to lighten a buttons background on click. So I did the following: <converter:ColorLightConverter x:Key="colorLightConverter" /> ... <Style BasedOn="{StaticResource default}" TargetType="{x:Type controls:Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type controls:Button}"> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="{Binding Path=Background.Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource colorLightConverter}}" /> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> <Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0"> ... </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> The converter: class ColorLightConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Color color = (Color)value; System.Drawing.Color lightColor = ControlPaint.Light(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)); return Color.FromArgb(lightColor.A, lightColor.R, lightColor.G, lightColor.B); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } But the converter isn't called when I click the button. I think there is anything wrong with the binding, but I can't see the error... Can you help me? Maybe I'm completely wrong. What I basically want to do: When clicking the button, take the current background color and lighten it. Not more...

    Read the article

  • Custom button with property as StaticResource

    - by alin
    I am trying to achieve the following thing: use an svg image into a custom button. In order to do this I created a Custom button: public class MainButton : Button { static MainButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MainButton), new FrameworkPropertyMetadata(typeof(MainButton))); } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(MainButton), new UIPropertyMetadata("")); public object Image { get { return (object)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(object), typeof(MainButton), new UIPropertyMetadata("")); } I took a svg file, opened it in inkscape and saved it as xaml file. I opened Themes.xaml and added the created xaml image as a ControlTemplate And the button style is: Style TargetType="{x:Type local:MainButton}" <StackPanel Canvas.Top="12" Canvas.Left="0" Canvas.ZIndex="2" Width="80"> <ContentControl x:Name="Img" Template="{StaticResource Home}" /> </StackPanel> <StackPanel x:Name="spText" Canvas.Top="45" Canvas.Left="1" Canvas.ZIndex="1" Width="80"> <TextBlock x:Name="Txt" Text="{Binding Path=(local:MainButton.Text), RelativeSource ={RelativeSource FindAncestor, AncestorType ={x:Type Button}}}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="14"/> </StackPanel> ... As you can see I have hardcoded the StaticResource name I want to be able to have a binding with property Image on this Template, something like So that I can set the Image property of the button with the name of the StaticResource I want. For example, having beside "Home" image, another one "Back" I would have two buttons in MainWindow declared like this: Any advice is kindly taken. Thank you for your time.

    Read the article

  • Applying correct bindings to WPF datatemplate to maximize reusability

    - by johncatfish
    Hi. I have a WPF application. I want to apply that datatemplate to a Listbox filled with records from Table02. Then, for each listboxitem I need to bind the combobox to the same database table (Table01), but for each listboxitem the selected item will vary. It will be a foreign key to Table01. <DataTemplate x:Key="Table01DataTemplate"> <Grid> <ComboBox ItemsSource="{Binding Model.IQueryable_Table01, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" SelectedValue="{Binding Table01_ForeignKey}" DisplayMemberPath="name" SelectedValuePath="id" /> <!-- Other stuff --> </Grid> </DataTemplate> <ListBox x:Name="lbTest" ItemTemplate="{StaticResource Table01DataTemplate}" /> <!-- In .cs file lbTest.DataContext = this; --> Notes: Model.IQueryable_Table01 is a property which encapsulates a Linq-to-sql call returning a IQueryable. lbTest will be filled by setting ItemsSource with a Linq-to-sql call. Is this a good way to do the bindings in a data template for a maximum reusability? I also thought of replacing AncestorType={x:Type Window} with lbTest.DataContext = this; AncestorType={x:Type Application} and lbTest.DataContext = App.Current; But it didn't work (Exception on loading) and I don't know if there's any caveats or down-sides to this approach. Is this good? Any suggestions or improvements? Thanks.

    Read the article

  • WPF Binding to variable / DependencyProperty

    - by Peter
    I'm playing around with WPF Binding and variables. Apparently one can only bind DependencyProperties. I have come up with the following, which works perfectly fine: The code-behind file: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public string Test { get { return (string)this.GetValue(TestProperty); } set { this.SetValue(TestProperty, value); } //set { this.SetValue(TestProperty, "BBB"); } } public static readonly DependencyProperty TestProperty = DependencyProperty.Register( "Test", typeof(string), typeof(MainWindow), new PropertyMetadata("CCC")); private void button1_Click(object sender, RoutedEventArgs e) { MessageBox.Show(Test); Test = "AAA"; MessageBox.Show(Test); } } XAML: <Window x:Class="WpfApplication3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Grid> <TextBox Height="31" HorizontalAlignment="Left" Margin="84,86,0,0" Name="textBox1" VerticalAlignment="Top" Width="152" Text="{Binding Test, Mode=TwoWay, diag:PresentationTraceSources.TraceLevel=High}"/> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="320,85,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> <TextBox Height="31" HorizontalAlignment="Left" Margin="84,138,0,0" Name="textBox2" Text="{Binding Test, Mode=TwoWay}" VerticalAlignment="Top" Width="152" /> </Grid> The two TextBoxes update one an other. And the Button sets them to "AAA". But now I replaced the Setter function with the one that is commented out (simulating some manipulation of the given value). I would expect that whenever the property value is changed it will be reset to "BBB". It does so when you press the button, that is when you set the property in code. But it does for some reason not affect the WPF Bindings, that is you can change the TextBox contents and thus the property, but apparently the Setter is never called. I wonder why that is so, and how one would go about to achive the expected behaviour.

    Read the article

  • [WPF] ExceptionValidationRule doesn't react to exceptions...

    - by Darmak
    Hi, I have an ExceptionValidationRule on my TextBox: <Window.Resources> <Style x:Key="textStyleTextBox" TargetType="TextBox"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /> </Trigger> </Style.Triggers> </Style> </Window.Resources> <TextBox x:Name="myTextBox" {Binding Path=MyProperty, ValidatesOnExceptions=True}" Style="{StaticResource ResourceKey=textStyleTextBox}" /> and MyProperty looks like that: private int myProperty; public int MyProperty { get { return myProperty; } set { if(value > 10) throw new ArgumentException("LOL that's an error"); myProperty = value; } } In DEBUG mode, application crashes with unhandled exception "LOL that's an error" (WPF Binding Engine doesn't catch this and I think it should...). In RELEASE mode, everything works fine. Can someone tell me, why the hell is this happening? And how can I fix this?

    Read the article

  • How to make DataGrid Row really fully selectable (clicking on non-cell area)

    - by Samuel
    The question might be a little misleading. Here is a screenshot of a DataGrid that has some dummy values (code provided below) Is there a way to make the white area not covered by a cell clickable? My intention: I want to have full row selection. This can be achieved by SelectionUnit="FullRow" which is fine but how can I make the white area implicitly select the entire row without expanding available cells in width and avoiding code behind Here is the repro code: Xaml: <Window x:Class="DGVRowSelectTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}"> <DataGrid ItemsSource="{Binding Names}" SelectionMode="Single" SelectionUnit="FullRow" > </DataGrid> </Window> Dummy Code behind of it (just sets the two entries up) using System.Collections.Generic; using System.Windows; namespace DGVRowSelectTest { public partial class MainWindow : Window { private IList<KeyValuePair<string, string>> _names = new List<KeyValuePair<string, string>>{new KeyValuePair<string, string>("A1", "A2"),new KeyValuePair<string, string>("B1","B2")}; public IList<KeyValuePair<string, string>> Names{get { return _names; }set { _names = value; }} public MainWindow() { InitializeComponent(); } } }

    Read the article

  • How can I incorporate a data bound list of MenuItems to another MenuItem in WPF?

    - by Julien Poulin
    I have a 'File' MenuItem were I would like to display a list of recently opened files. Here is the xaml I have now: <MenuItem Header="File}"> <MenuItem Header="Preferences..." Command="{Binding ShowOptionsViewCommand}" /> <Separator /> <ItemsControl ItemsSource="{Binding RecentFiles}"> <ItemsControl.ItemTemplate> <DataTemplate> <MenuItem Header="{Binding DisplayPath}" CommandParameter="{Binding}" Command="{Binding Path=DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"> </MenuItem> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <Separator /> <MenuItem Header="Exit" Command="{Binding CloseCommand}" /> </MenuItem> However, when I use this code, there is a weird offset around the MenuItems and it looks like there is a container around them. How can I get rid of that? Here is a screenshot of what it looks like:

    Read the article

  • progressbar not updating binding

    - by BoteRock
    I am trying to make a progress bar that updates when a property value changes I have followed other questions but i don't know what is wrong with it. This is XAML code: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow" Title="MainWindow"> <Grid Margin="0,0,-8,1"> <ProgressBar Value="{Binding Progreso, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}" Margin="105,95,207,350"/> <Button Content="Button" Click="Button_Click" Margin="218,232,333,217"/> </Grid> </Window> it is basically a progress bar with the binding and a button with a listener that increases Progreso by 10 this is the C# code: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string sProp) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(sProp)); } } float progreso = 10; public float Progreso { get { return progreso; } set { progreso = value; NotifyPropertyChanged("Progreso"); } } private void Button_Click(object sender, RoutedEventArgs e) { this.Progreso = this.Progreso + 10; } } I tried to keep it simple but I couldn't get it to work, any help with this would be appreciated. edit: I've also tried UpdateSourceTrigger=PropertyChanged and that didn't work either

    Read the article

  • Silverlight 5 &ndash; What&rsquo;s New? (Including Screenshots &amp; Code Snippets)

    - by mbcrump
    Silverlight 5 is coming next year (2011) and this blog post will tell you what you need to know before the beta ships. First, let me address people saying that it is dead after PDC 2010. I believe that it’s best to see what the market is doing, not the vendor. Below is a list of companies that are developing Silverlight 4 applications shown during the Silverlight Firestarter. Some of the companies have shipped and some haven’t. It’s just great to see the actual company names that are working on Silverlight instead of “people are developing for Silverlight”. The next thing that I wanted to point out was that HTML5, WPF and Silverlight can co-exist. In case you missed Scott Gutherie’s keynote, they actually had a slide with all three stacked together. This shows Microsoft will be heavily investing in each technology.  Even I, a Silverlight developer, am reading Pro HTML5. Microsoft said that according to the Silverlight Feature Voting site, 21k votes were entered. Microsoft has implemented about 70% of these votes in Silverlight 5. That is an amazing number, and I am crossing my fingers that Microsoft bundles Silverlight with Windows 8. Let’s get started… what’s new in Silverlight 5? I am going to show you some great application and actual code shown during the Firestarter event. Media Hardware Video Decode – Instead of using CPU to decode, we will offload it to GPU. This will allow netbooks, etc to play videos. Trickplay – Variable Speed Playback – Pitch Correction (If you speed up someone talking they won’t sound like a chipmunk). Power Management – Less battery when playing video. Screensavers will no longer kick in if watching a video. If you pause a video then screensaver will kick in. Remote Control Support – This will allow users to control playback functions like Pause, Rewind and Fastforward. IIS Media Services 4 has shipped and now supports Azure. Data Binding Layout Transitions – Just with a few lines of XAML you can create a really rich experience that is not using Storyboards or animations. RelativeSource FindAncestor – Ancestor RelativeSource bindings make it much easier for a DataTemplate to bind to a property on a container control. Custom Markup Extensions – Markup extensions allow code to be run at XAML parse time for both properties and event handlers. This is great for MVVM support. Changing Styles during Runtime By Binding in Style Setters – Changing Styles at runtime used to be a real pain in Silverlight 4, now it’s much easier. Binding in style setters allows bindings to reference other properties. XAML Debugging – Below you can see that we set a breakpoint in XAML. This shows us exactly what is going on with our binding.  WCF & RIA Services WS-Trust Support – Taken from Wikipedia: WS-Trust is a WS-* specification and OASIS standard that provides extensions to WS-Security, specifically dealing with the issuing, renewing, and validating of security tokens, as well as with ways to establish, assess the presence of, and broker trust relationships between participants in a secure message exchange. You can reduce network latency by using a background thread for networking. Supports Azure now.  Text and Printing Improved text clarity that enables better text rendering. Multi-column text flow, Character tracking and leading support, and full OpenType font support.  Includes a new Postscript Vector Printing API that provides control over what you print . Pivot functionality baked into Silverlight 5 SDK. Graphics Immediate mode graphics support that will enable you to use the GPU and 3D graphics supports. Take a look at what was shown in the demos below. 1) 3D view of the Earth – not really a real-world application though. A doctor’s portal. This demo really stood out for me as it shows what we can do with the 3D / GPU support. Out of Browser OOB applications can now create and manage childwindows as shown in the screenshot below.  Trusted OOB applications can use P/Invoke to call Win32 APIs and unmanaged libraries.  Enterprise Group Policy Support allow enterprises to lock down or up the sandbox capabilities of Silverlight 5 applications. In this demo, he tore the “notes” off of the application and it appeared in a new window. See the black arrow below. In this demo, he connected a USB Device which fired off a local Win32 application that provided the data off the USB stick to Silverlight. Another demo of a Silverlight 5 application exporting data right into Excel running inside of browser. Testing They demoed Coded UI, which is available now in the Visual Studio Feature Pack 2. This will allow you to create automated testing without writing any code manually. Performance: Microsoft has worked to improve the Silverlight startup time. Silverlight 5 provides 64-bit browser support.  Silverlight 5 also provides IE9 Hardware acceleration.   I am looking forward to Silverlight 5 and I hope you are too. Thanks for reading and I hope you visit again soon.  Subscribe to my feed CodeProject

    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

  • WPF - Only want one expander open at a time in grouped Listbox

    - by Portsmouth
    I have a UserControl with a templated grouped listbox with expanders and only want one expander open at any time. I have browsed through the site but haven't found anything except binding the IsExpanded to IsSelected which isn't quite what I want. I am trying to put some code in the Expanded event that would loop through Expanders and close all the ones that aren't the expander passed in the Expanded event. I can't seem to figure out how to get at them. I've tried ListBox.Items.Groups but didn't see how to get at them and tried ListBox.ItemContainerGenerator.ContainerFromItem (or Index) but nothing came back. Thanks <ListBox Name="ListBox"> <ListBox.GroupStyle> <GroupStyle> <GroupStyle.ContainerStyle> <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <Border BorderBrush="CadetBlue" BorderThickness="1"> <Expander BorderThickness="0,0,0,1" Expanded="Expander_Expanded" Focusable="False" IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType= {x:Type ListBoxItem}}}" > <Expander.Header> <Grid> <StackPanel Height="30" Orientation="Horizontal"> <TextBlock Foreground="Navy" FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" MinWidth="200" Padding="3" VerticalAlignment="Center" /> <TextBlock Foreground="Navy" FontWeight="Bold" Text=" Setups: " VerticalAlignment="Center" HorizontalAlignment="Right"/> <TextBlock Foreground="Navy" FontWeight="Bold" Text="{Binding Path=ItemCount}" VerticalAlignment="Center" HorizontalAlignment="Right" /> </StackPanel> </Grid> </Expander.Header> <Expander.Content> <Grid Background="white" > <ItemsPresenter /> </Grid> </Expander.Content> <Expander.Style > <Style TargetType="{x:Type Expander}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Color="WhiteSmoke" Offset="0.0" /> <GradientStop Color="Orange" Offset="1.0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsMouseOver" Value="false" <Setter Property="Background"> <Setter.Value>

    Read the article

  • Databinding to ObservableCollection in a different UserControl?

    - by Dave
    Question re-written on 2010-03-24 I have two UserControls, where one is a dialog that has a TabControl, and the other is one that appears within said TabControl. I'll just call them CandyDialog and CandyNameViewer for simplicity's sake. There's also a data management class called Tracker that manages information storage, which for all intents and purposes just exposes a public property that is an ObservableCollection. I display the CandyNameViewer in CandyDialog via code behind, like this: private void CandyDialog_Loaded( object sender, RoutedEventArgs e) { _candyviewer = new CandyViewer(); _candyviewer.DataContext = _tracker; candy_tab.Content = _candyviewer; } The CandyViewer's XAML looks like this (edited for kaxaml): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <DataTemplate x:Key="CandyItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Text="{Binding CandyName}" Margin="3"></TextBox> <!-- just binding to DataContext ends up using InventoryItem as parent, so we need to get to the UserControl --> <ComboBox Grid.Column="1" SelectedItem="{Binding SelectedCandy, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CandyNames}" Margin="3"></ComboBox> </Grid> </DataTemplate> </Page.Resources> <Grid> <ListBox DockPanel.Dock="Top" ItemsSource="{Binding CandyBoxContents, Mode=TwoWay}" ItemTemplate="{StaticResource CandyItemTemplate}" /> </Grid> </Page> Now everything works fine when the controls are loaded. As long as CandyNames is populated first, and then the consumer UserControl is displayed, all of the names are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified from the model, those changes are not reflected in the consumer UserControl! I've never had this problem before; all of my previous uses of ObservableCollection updated fine, although in those cases I wasn't databinding across assemblies. Although I am currently only adding and removing candy names to/from the ObservableCollection, at a later date I will likely also allow renaming from the model side. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • How to get rid of annoying HorizontalContentAlignment binding warning?

    - by marco.ragogna
    I am working on a large WPF project and during debug my output window is filled with these annoying warnings: System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name=''); target property is 'HorizontalContentAlignment' (type ' HorizontalAlignment') In the specific example ComboBoxItem is styled in this way: <Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}"> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBoxItem}"> <Border Name="bd" Padding="4,4,4,4" SnapsToDevicePixels="True" CornerRadius="2,2,2,2"> <ContentPresenter /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsHighlighted" Value="true"> <Setter TargetName="bd" Property="Background" Value="{StaticResource MediumBrush}"/> <Setter TargetName="bd" Property="Padding" Value="4,4,4,4"/> <Setter TargetName="bd" Property="CornerRadius" Value="2,2,2,2"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> I know that the problem is generated by the default theme definition for ComboBoxItem that contains things like: <Setter Property="Control.HorizontalContentAlignment"> <Setter.Value> <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" /> </Setter.Value> </Setter> but I also thought that using <Setter Property="OverridesDefaultStyle" Value="True"/> would taken care of the problem, and instead warnings are still there. Any help is really appreciated

    Read the article

  • Trouble animating RadialGradientBrush in WPF

    - by emddudley
    I'm trying to animate a RadialGradientBrush in my application. I get the super helpful exception: Additional information: 'System.Windows.Style' value cannot be assigned to property 'Style' of object 'System.Windows.Controls.Border'. '[Unknown]' property does not point to a DependencyObject in path '(0).(1).[0].(2)'. Error at object 'System.Windows.Style' in markup file 'Eng.Modules.Core;component/system/grid/systemgridview.xaml' Line 252 Position 51. I know it's something wrong with the indirect property targeting or partial path qualification in my DoubleAnimation's Storyboard.TargetProperty attribute. Any ideas? <Border> <Border.Resources> <RadialGradientBrush x:Key="SomeBrush"> <RadialGradientBrush.GradientStops> <GradientStop Color="White" Offset="0" /> <GradientStop Color="Gold" Offset="1" /> </RadialGradientBrush.GradientStops> </RadialGradientBrush> </Border.Resources> <Border.Style> <Style TargetType="{x:Type Border}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}}" Value="True"> <Setter Property="Background" Value="{StaticResource SomeBrush}" /> <DataTrigger.EnterActions> <BeginStoryboard x:Name="SomeStoryBoard"> <Storyboard> <!-- RIGHT HERE --> <DoubleAnimation Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" From="0" To="1" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <RemoveStoryboard BeginStoryboardName="SomeStoryBoard" /> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </Border.Style> </Border>

    Read the article

  • WPF Open Combobox popup on Focus or GotFocus

    - by ashish.magroria
    Hi, I am trying to open the combobox popup when it is focused using Style/Event Trigger I used the following code in my Combobox control Template: <ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}"> <Grid > <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/> <ContentPresenter HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/> <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/> <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide"> <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True"> <Border x:Name="DropDownBorder" Background="{DynamicResource ShadeBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1"/> <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/> </ScrollViewer> </Grid> </Popup> </Grid> <ControlTemplate.Triggers> **<Trigger Property="IsMouseOver" Value="True"> <Setter Property="IsOpen" Value="True" TargetName="Popup"/> </Trigger>** </ControlTemplate.Triggers> </ControlTemplate> But nothing happens with this code. So I trid the following Event trigger in ControlTemplate.Triggers <EventTrigger RoutedEvent="UIElement.GotFocus"> <BeginStoryboard> <Storyboard > <BooleanAnimationUsingKeyFrames Storyboard.TargetName="Popup" Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd"> <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True" /> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="UIElement.LostFocus"> <BeginStoryboard> <Storyboard > <BooleanAnimationUsingKeyFrames Storyboard.TargetName="Popup" Storyboard.TargetProperty="IsOpen" FillBehavior="HoldEnd"> <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" /> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> Now this helps open the popup on focus, but when I select any item from dropdown the pop up doesnt disappear as usual; it stays open. it closes only after I click somewhere else in the window. Can someone please suggest the proper way to do this Thanks in advance

    Read the article

  • WPF - Only want one expander open at a time

    - by Portsmouth
    I have a UserControl with a templated grouped listbox with expanders and only want one expander open at any time. I have browsed through the site but haven't found anything except binding the IsExpanded to IsSelected which isn't quite what I want. I am trying to put some code in the Expanded event that would loop through Expanders and close all the ones that aren't the expander passed in the Expanded event. I can't seem to figure out how to get at them. I've tried ListBox.Items.Groups but didn't see how to get at them and tried ListBox.ItemContainerGenerator.ContainerFromItem (or Index) but nothing came back. Thanks <ListBox Name="ListBox"> <ListBox.GroupStyle > <GroupStyle> <GroupStyle.ContainerStyle> <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <Border BorderBrush="CadetBlue" BorderThickness="1"> <Expander BorderThickness="0,0,0,1" Expanded="Expander_Expanded" Focusable="False" IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType= {x:Type ListBoxItem}}}" > <Expander.Header> <Grid> <StackPanel Height="30" Orientation="Horizontal"> <TextBlock Foreground="Navy" FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" MinWidth="200" Padding="3" VerticalAlignment="Center" /> <TextBlock Foreground="Navy" FontWeight="Bold" Text=" Setups: " VerticalAlignment="Center" HorizontalAlignment="Right"/> <TextBlock Foreground="Navy" FontWeight="Bold" Text="{Binding Path=ItemCount}" VerticalAlignment="Center" HorizontalAlignment="Right" /> </StackPanel> </Grid> </Expander.Header> <Expander.Content> <Grid Background="white" > <ItemsPresenter /> </Grid> </Expander.Content> <Expander.Style > <Style TargetType="{x:Type Expander}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Color="WhiteSmoke" Offset="0.0" /> <GradientStop Color="Orange" Offset="1.0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsMouseOver" Value="false" <Setter Property="Background"> <Setter.Value> </code>

    Read the article

  • WPF Custom Control - Designer looks fine, but I get a runtime issue...

    - by myermian
    MainWindow.xaml <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:MyStuff;assembly=MyStuff" Title="MainWindow" Height="350" Width="525"> <Grid> <TabControl Margin="5"> <TabItem Header="Start Page" /> <my:XTabItem Header="Tab 1" Image="Resources/icon1.png" /> </TabControl> </Grid> </Window> Generic.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyStuff" > <!-- XTabItem --> <Style TargetType="{x:Type local:XTabItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:XTabItem}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding Path=Image, RelativeSource={RelativeSource TemplatedParent}}" Stretch="UniformToFill" MaxHeight="24" /> <TextBlock Text="{TemplateBinding Header}" /> <Button Content="X" /> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> XTabItem.cs using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace MyStuff { public class XTabItem : TabItem { #region Dependency Properties public static readonly DependencyProperty ImageProperty; #endregion #region Constructors / Initializer static XTabItem() { //Initialize the control as "lookless". DefaultStyleKeyProperty.OverrideMetadata(typeof(XTabItem), new FrameworkPropertyMetadata(typeof(XTabItem))); //Setup the dependency properties. ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(XTabItem), new UIPropertyMetadata(null)); } #endregion #region Custom Control Properties (Image) /// <summary> /// The image (icon) displayed by inside the tab header. /// </summary> /// <remarks>The image is specified in XAML as an absolute or relative path.</remarks> [Description("The image displayed by the button"), Category("Optional Properties")] public ImageSource Image { get { return (ImageSource)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } #endregion } } Exception at line #9 () : XamlParseException : 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '9' and line position '27'.

    Read the article

  • WPF - ListBox ignores Style When ItemsSource is bound

    - by Andy T
    Hi, I have created styled a ListBox in WPF so that it is rendered as a checkbox list. When I populate the ListBox's items manually, the styling works perfectly. However, when I instead bind the ItemsSource of the ListBox to a static resource (an ItemsControl containing the required items), the styling is completely dropped. Here's the style: <Style x:Key="CheckBoxListStyle" TargetType="ListBox"> <Style.Resources> <Style TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Grid Margin="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/> <ContentPresenter Grid.Column="1" Margin="2,0,0,0" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Style.Resources> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" /> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Background" Value="Transparent" /> </Style> Here's the code for the ListBox that shows the style correctly: <ListBox x:Name="ColumnsList" Grid.Column="0" Grid.Row="0" Style="{StaticResource CheckBoxListStyle}" BorderThickness="1"> <ListBox.Items> <ListBoxItem>Test</ListBoxItem> <ListBoxItem>Test2</ListBoxItem> <ListBoxItem>Test3</ListBoxItem> </ListBox.Items> </ListBox> Here's the code for the ListBox that ignores the style: <ListBox x:Name="ColumnsList2" Grid.Column="0" Grid.Row="0" Style="{StaticResource CheckBoxListStyle}" BorderThickness="1" ItemsSource="{Binding Source={StaticResource Test1}, Path=Items}"> </ListBox> Hoping someone can help - I'm pretty new to all this and have tried everything I can think of, but everything I've read leads me to believe that setting ItemsSource should have the same outcome as setting the items manually, so I can't see any reason why this would not work. Thanks, AT

    Read the article

  • AdornerDecorator and tab stop issues

    - by Trev
    Hi, I am using IDataErrorInfo to validate and indicate errors in my text boxes. I am finding I have to tab once for the text box and once for the adornerdecorator. I have an error template: <ControlTemplate x:Key="ErrorTemplate"> <StackPanel KeyboardNavigation.IsTabStop="False" > <Border KeyboardNavigation.IsTabStop="False" BorderBrush="Red" BorderThickness="1" Padding="2" CornerRadius="2"> <AdornedElementPlaceholder KeyboardNavigation.IsTabStop="False" /> </Border> </StackPanel> </ControlTemplate> a textbox template: <Style x:Key="TextBoxInError" TargetType="{x:Type TextBox}"> <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="Margin" Value="0,5,0,5"/> <Setter Property="AllowDrop" Value="true"/> <Setter Property="HorizontalContentAlignment" Value="left"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Grid KeyboardNavigation.IsTabStop="False" > <Border KeyboardNavigation.IsTabStop="False" x:Name="Border" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" Padding="2" CornerRadius="2"> <ScrollViewer IsTabStop="False" Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleScrollViewer}" Background="{TemplateBinding Background}"/> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="Gray"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> and declare a text box like this: <AdornerDecorator KeyboardNavigation.IsTabStop="False" > <TextBox Margin="5,5,5,3" x:Name="txtName" IsEnabled="{Binding EditMode}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Text="{Binding ApplicationName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Height="25" MaxLength="50" MaxLines="1" Style="{StaticResource TextBoxInError}"/> </AdornerDecorator> If the adorner is round one text box as above then I tab once to leave the text box and once to leave the 'adornment' (it seems) If I have the adorner around a stackpanel of text boxes then I tab once each for the text boxes then have to go back through all the 'adornments' in turn. When tabbing through the adornments the focus goes on the red border defined in the control template.. any ideas? thanks

    Read the article

  • Using a Button to navigate to another Page in a NavigationWindow

    - by Will
    I'm trying to use the navigation command framework in WPF to navigate between Pages within a WPF application (desktop; not XBAP or Silverlight). I believe I have everything configured correctly, yet its not working. I build and run without errors, I'm not getting any binding errors in the Output window, but my navigation button is disabled. Here's the app.xaml for a sample app: <Application x:Class="Navigation.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="First.xaml"> </Application> Note the StartupUri points to First.xaml. First.xaml is a Page. WPF automatically hosts my page in a NavigationWindow. Here's First.xaml: <Page x:Class="Navigation.First" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="First"> <Grid> <Button CommandParameter="/Second.xaml" CommandTarget="{Binding RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type NavigationWindow}}}" Command="NavigationCommands.GoToPage" Content="Go!"/> </Grid> </Page> The button's CommandTarget is set to the NavigationWindow. The command is GoToPage, and the page is /Second.xaml. I've tried setting the CommandTarget to the containing Page, the CommandParameter to "Second.xaml" (First.xaml and Second.xaml are both in the root of the solution), and I've tried leaving the CommandTarget empty. I've also tried setting the Path to the Binding to various navigational-related public properties on the NavigationWindow. Nothing has worked so far. What am I missing here? I really don't want to do my navigation in code. Clarification. If, instead of using a button, I use a Hyperlink: <Grid> <TextBlock> <Hyperlink NavigateUri="Second.xaml">Go! </Hyperlink> </TextBlock> </Grid> everything works as expected. However, my UI requirements means that using a Hyperlink is right out. I need a big fatty button for people to press. That's why I want to use the button to navigate. I just want to know how I can get the Button to provide the same ability that the Hyperlink does in this case.

    Read the article

  • How to assign WPF resources to other resource tags

    - by Tom
    This is quite obscure, I may just be missing something extremely simple. Scenario 1 Lets say I create a gradient brush, like this in my <Window.Resources> section: <LinearGradientBrush x:Key="GridRowSelectedBackBrushGradient" StartPoint="0,0" EndPoint="0,1"> <GradientStop Color="#404040" Offset="0.0" /> <GradientStop Color="#404040" Offset="0.5" /> <GradientStop Color="#000000" Offset="0.6" /> <GradientStop Color="#000000" Offset="1.0" /> </LinearGradientBrush> Then much later on, I want to override the HighlightBrushKey for a DataGrid. I have basically done it like this (horrible); <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" GradientStops="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=GradientStops}" StartPoint="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=StartPoint}" EndPoint="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=EndPoint}" /> This is obviously not the most slick way of referencing a resource. I also came up with the following problem, which is almost identical. Scenario 2 Say I created two colors in my <Window.Resources> markup, like so: <SolidColorBrush x:Key="DataGridRowBackgroundBrush" Color="#EAF2FB" /> <SolidColorBrush x:Key="DataGridRowBackgroundAltBrush" Color="#FFFFFF" /> Then later on, I want to supply them in an Array, which feeds the ConverterParameter on a Binding so I can supply the custom Converter with my static resource instances: <Setter Property="Background"> <Setter.Value> <Binding RelativeSource="{RelativeSource Mode=Self}" Converter="{StaticResource BackgroundBrushConverter}"> <Binding.ConverterParameter> <x:Array Type="{x:Type Brush}"> <SolidColorBrush Color="{Binding Source={StaticResource DataGridRowBackgroundBrush}, Path=Color}" /> <SolidColorBrush Color="{Binding Source={StaticResource DataGridRowBackgroundAltBrush}, Path=Color}" /> </x:Array> </Binding.ConverterParameter> </Binding> </Setter.Value> </Setter> What I've done is attempt to rereference an existing resource, but in my efforts I've actually recreated the resource, and bound the properties so they match. Again, this is not ideal. Because I've now hit this problem at least twice, is there a better way? Thanks, Tom

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >