Search Results

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

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

  • Why won't IsChecked change on this toggle button?

    - by cjroebuck
    I have the following xaml for a toggle button: <ToggleButton Margin="0,3" Grid.Row="3" Grid.ColumnSpan="2" Command="{Binding DataContext.SelectAllCommand, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"> <ToggleButton.Style> <Style TargetType="{x:Type ToggleButton}"> <Setter Property="Content" Value="Select All"/> <Style.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="Content" Value="Select None"/> <Setter Property="Command" Value="{Binding DataContext.SelectNoneCommand, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/> </Trigger> </Style.Triggers> </Style> </ToggleButton.Style> </ToggleButton> But the IsChecked property never gets updated when clicking the button. If I use snoop and force the IsChecked to True then the trigger kicks in.

    Read the article

  • Set Validation Tooltip in CodeBehind instead of XAML

    - by KrisTrip
    I would like to know how to translate the following code to codebehind instead of XAML: <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> The part I can't figure out is the Path portion. I have the following but it doesn't work: new Trigger { Property = Validation.HasErrorProperty, Value = true, Setters = { new Setter { Property = Control.ToolTipProperty, // This part doesn't seem to work Value = new Binding("(Validation.Errors)[0].ErrorContent"){RelativeSource = RelativeSource.Self} } } } Help?

    Read the article

  • Puzzle - Dynamically change data template control from another data template

    - by Burt
    I have a DataTemplate that contains an Expander with a border in the header. I want the header border to have round corners when collapsed and straight bottom corners when expanded. What would best practice be for achieving this (bonus points for code samples as I am new to XAML)? This is the template that holds the expander: <DataTemplate x:Key="A"> <StackPanel> <Expander Name="ProjectExpander" Header="{Binding .}" HeaderTemplate="{StaticResource B}" > <StackPanel> <Border CornerRadius="0,0,2,2"> This is the expander datatemplate: <DataTemplate x:Key="B"> <Border x:Name="ProjectExpanderHeader" CornerRadius="{Binding local:ItemUserControl.ProjectHeaderBorderRadius, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}}" Background="{StaticResource ItemGradient}" HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}, Mode=OneWayToSource}"> <local:ItemContentsUserControl Height="30"/> </Border> </DataTemplate>

    Read the article

  • Custom ProgressBarBrushConverter Not Filling In ProgressBar

    - by Wonko the Sane
    Hello All, I am attempting to create a custom ProgressBarBrushConverter, based on information from here and here. However, when it runs, the progress is not being shown. If I use the code found in the links, it appears to work correctly. Here is the converter in question: public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { ProgressBar progressBar = null; foreach (object value in values) { if (value is ProgressBar) { progressBar = value as ProgressBar; break; } } if (progressBar == null) return DependencyProperty.UnsetValue; FrameworkElement indicator = progressBar.Template.FindName("PART_Indicator", progressBar) as FrameworkElement; DrawingBrush drawingBrush = new DrawingBrush(); drawingBrush.Viewport = drawingBrush.Viewbox = new Rect(0.0, 0.0, indicator.ActualWidth, indicator.ActualHeight); drawingBrush.ViewportUnits = BrushMappingMode.Absolute; drawingBrush.TileMode = TileMode.None; drawingBrush.Stretch = Stretch.None; DrawingGroup group = new DrawingGroup(); DrawingContext context = group.Open(); context.DrawRectangle(progressBar.Foreground, null, new Rect(0.0, 0.0, indicator.ActualWidth, indicator.ActualHeight)); context.Close(); drawingBrush.Drawing = group; return drawingBrush; } Here is the ControlTemplate (the MultiBinding is to make sure that the converter is called whenever the Value or IsIndeterminate properties are changed): <ControlTemplate x:Key="customProgressBarTemplate" TargetType="{x:Type ProgressBar}"> <Grid> <Path x:Name="PART_Track" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill" StrokeLineJoin="Round" Stroke="#DDCBCBCB" StrokeThickness="4" Data="M 20,100 L 80,10 C 100,120 160,140 190,180 S 160,220 130,180 T 120,150 20,100 Z "> <Path.Fill> <MultiBinding> <MultiBinding.Converter> <local:ProgressBarBrushConverter /> </MultiBinding.Converter> <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ProgressBar}}" /> <Binding Path="IsIndeterminate" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </Path.Fill> <!--<Path.LayoutTransform> <RotateTransform Angle="180" CenterX="190" CenterY="110" /> </Path.LayoutTransform>--> </Path> <Rectangle x:Name="PART_Indicator" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="1" /> </Grid> </ControlTemplate> Finally, the Window code (fairly straightforward - it just animates progress from 0 to 100 and back again): <ProgressBar x:Name="progress" Template="{StaticResource customProgressBarTemplate}" Foreground="Red"> <ProgressBar.Triggers> <EventTrigger RoutedEvent="ProgressBar.Loaded"> <BeginStoryboard x:Name="storyAnimate"> <Storyboard> <DoubleAnimationUsingKeyFrames Duration="0:0:12" AutoReverse="True" FillBehavior="Stop" RepeatBehavior="Forever" Storyboard.TargetName="progress" Storyboard.TargetProperty="(ProgressBar.Value)"> <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" /> <LinearDoubleKeyFrame Value="100" KeyTime="0:0:5" /> <LinearDoubleKeyFrame Value="100" KeyTime="0:0:6" /> <LinearDoubleKeyFrame Value="0" KeyTime="0:0:11" /> <LinearDoubleKeyFrame Value="0" KeyTime="0:0:12" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </ProgressBar.Triggers> </ProgressBar> I am thinking that the problem is in the DrawRectangle call in the Convert method, but setting a TracePoint on it shows what appear to be valid values for the Rect. What am I missing here? Thanks, wTs

    Read the article

  • Need additional help with binding multiple CommandParameters using MultiBinding

    - by Dave
    I need to have a command handler for a ToggleButton that can take multiple parameters, namely the IsChecked property of said ToggleButton, along with a constant value, which could be a string, byte, int... doesn't matter. I found this great question on SO and followed the answer's link and read up on MultiBinding and IMultiValueConverter. It went really smoothly until I had to write the MultiBinding, when I realized that I also need to pass a constant value and couldn't do something like <Binding Value="1" /> I then came across another similar question that Kent Boogaart answered, and then I started to think about ways that I could get around this. One possible way is to not use MVVM and simply add the Tag property to my ToggleButton, in which case my MultiBinding would look like this: <MultiBinding Converter="{StaticResource MyConverter}"> <MultiBinding.Bindings> <Binding Path="IsChecked" /> <Binding Path="Tag" /> </MultiBinding.Bindings> </MultiBinding> Kent had made a comment along the lines of, "if you're using MVVM you should be able to get around this issue". However, I'm not sure that's an option for me, even though I have adopted MVVM as my WPF pattern of necessity choice. The reason why I say this is that I have wayyyy more than one ToggleButton in the UserControl, and each of the ToggleButtons' Commands need to call the same function. But since they are ToggleButtons, I can't use the property bound to IsChecked in the ViewModel, because I don't know which one was last clicked. I suppose I could add another private property to keep track of this, but it seems a little silly. As far as the constant goes, I could probably get rid of this if I did the tracking idea, but not sure of any other way to get around it. Does anyone have good suggestions for me here? :) EDIT -- ok, so I need to update my bindings, which still don't work quite right: <ToggleButton Tag="1" Command="{Binding MyCommand}" Style="{StaticResource PassFailToggleButtonStyle}" HorizontalContentAlignment="Center" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"> <ToggleButton.CommandParameter> <MultiBinding Converter="{StaticResource MyConverter}"> <MultiBinding.Bindings> <Binding Path="IsChecked" RelativeSource="{RelativeSource Mode=Self}" /> <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}" /> </MultiBinding.Bindings> </MultiBinding> </ToggleButton.CommandParameter> </ToggleButton> IsChecked was working, but not Tag. I just realized that Tag is a string... duh. It's working now! The key was to use a RelativeSource of Self.

    Read the article

  • WPF TextBox.SelectAll () doesn't work

    - by Zoliq
    Hi! I have used the following template in my project: <DataTemplate x:Key="textBoxDataTemplate"> <TextBox Name="textBox" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" Tag="{Binding}" PreviewKeyDown="cellValueTextBoxKeyDown"> <TextBox.Text> <MultiBinding Converter="{StaticResource intToStringMultiConverter}"> <Binding Path="CellValue" Mode="TwoWay"> <Binding.ValidationRules> <y:MatrixCellValueRule MaxValue="200" /> </Binding.ValidationRules> </Binding> <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type y:MatrixGrid}}" Path="Tag" Mode="OneWay" /> </MultiBinding> </TextBox.Text> </TextBox> </DataTemplate> I used this template to create an editable matrix for the user. The user is able to navigate from cell to cell within the matrix and I would like to highlight the data in the selected textbox but it doesn't work. I called TextBox.Focus () and TextBox.SelectAll () to achieve the effect but nothing. The Focus () works but the text never gets highlighted. Any help is welcome and appreciated.

    Read the article

  • WPF Constrain the resize of a canvas' child object to the dimensions of the canvas

    - by Scott
    Given the following XAML: <Window x:Class="AdornerTesting.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="500" Width="500" Loaded="Window_Loaded"> <Grid Name="grid"> <Canvas Name="canvas" Width="400" Height="400" Background="LightGoldenrodYellow"> <RichTextBox Name="richTextBox" Canvas.Top="10" Canvas.Left="10" BorderBrush="Black" BorderThickness="2" Width="200" Height="200" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}},Path=ActualWidth}" MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}},Path=ActualHeight}"/> </Canvas> </Grid> </Window> and a set of adorners being added to the RichTextBox in the Loaded event like so: AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(richTextBox); adornerLayer.Add(new ResizeAdorner(richTextBox)); How do I keep from being able to resize the RichTextBox beyond the visble bounds of the Canvas? The ResizeAdorner is essentially the same code that can be found in the MSDN adorner example and it works just fine. Should I be doing something with the bindings of MaxWidth and MaxHeight in the code-behind to calculate how the RichTextBox can be resized? Or is there a way to do this in XAML?

    Read the article

  • WPF DataBinding to standard CLR properties in code-behind

    - by nukefusion
    Hi everyone, Just learning WPF databinding and have a gap in my understanding. I've seen a few similar questions on StackOverflow, but I'm still struggling in determining what I have done wrong. I have a simple Person class with a Firstname and Surname property (standard CLR properties). I also have a standard CLR property on my Window class that exposes an instance of Person. I've then got some XAML, with two methods of binding. The first works, the second doesn't. Can anybody help me to understand why the second method fails? There's no binding error message in the Output log. <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" Title="Window1" Height="300" Width="300" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=MyPerson}"> <StackPanel> <Label>My Person</Label> <WrapPanel> <Label>First Name:</Label> <Label Content="{Binding RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}, Path=MyPerson.FirstName}"></Label> </WrapPanel> <WrapPanel> <Label>Last Name:</Label> <Label Content="{Binding MyPerson.Surname}"></Label> </WrapPanel> </StackPanel> Edit: Ok, thanks so far. I've changed the second expression to: <Label Content="{Binding Surname}"></Label> I still can't get it to work though!

    Read the article

  • wpf error template - red box still visible on collapse of an expander

    - by Andy Clarke
    Hi, I'm doing some validation on the DataSource of TextBox that's within an Expander and have found that once a validation error has been triggered, if I collapse the Expander, the red box stays where the TextBox would have been. <Expander Header="Blah Blah Blah"> <TextBox Name="TextBox" Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}" Text="{Binding Path=Blah, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> </Expander> I've tried to get round this by binding the visibility of the Error Template to the Expander, however I think there's something wrong with the binding. <local:NotVisibleConverter x:Key="NotVisibleConverter" /> <ControlTemplate x:Key="TextBoxErrorTemplate"> <DockPanel> <Border BorderBrush="Red" BorderThickness="2" Visibility="{Binding Path=IsExpanded, Converter={StaticResource NotVisibleConverter}, RelativeSource={RelativeSource AncestorType=Expander}}" > <AdornedElementPlaceholder Name="MyAdorner" /> </Border> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> I guess I've gone wrong with my binding, can someone put me back on track please? Alternatively does anyone know another solution to the ErrorTemplate still being visible on the collapse of an Expander?

    Read the article

  • How do I ensure only the headers are shown for the first item in an ItemsControl in WPF?

    - by Dan Ryan
    I am using MVVM binding an ObservableCollection of children to an ItemsControl. The ItemsControl contains a UserControl used to style the UI for the children. <ItemsControl ItemsSource="{Binding Documents}"> <ItemsControl.ItemTemplate> <DataTemplate> <View:DocumentView Margin="0, 10, 0, 0" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> I want to show a header row for the contents of the ItemsControl but only want to show this once at the top (not for every child). How can I implement this behaviour in the DocumentView user control? Fyi I am using a Grid layout to style the child rows: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="34"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="*" /> <ColumnDefinition Width="60" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock Grid.ColumnSpan="4" Grid.Row="0" Text="Should only show this at the top"></TextBlock> <Image Grid.Column="0" Grid.Row="1" Height="24" Width="24" Source="/Beazley.Documents.Presentation;component/Icons/error.png"></Image> <ComboBox Grid.Column="1" Grid.Row="1" Name="ContentTypes" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type View:MainView}}, Path=DataContext.ContentTypes}" SelectedValue="{Binding ContentType}"/> <TextBox Grid.Column="2" Grid.Row="1" Text="{Binding Path=FileName}"/> <Button Grid.Column="3" Grid.Row="1" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type View:MainView}}, Path=DataContext.RemoveFile}" CommandParameter="{Binding}">Remove</Button> </Grid>

    Read the article

  • How can I control the height of a ListView in WPF, using a complex DataTemplate with DataTriggers?

    - by Rob Perkins
    I have a ListView element with a DataTemplate for each ListViewItem defined as follows. When run, the ListView's height is not collapsed onto the items in the view, which is undesirable behavior: <DataTemplate x:Key="LicenseItemTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding company}"></TextBlock> <Grid Grid.Row="1" Style="{StaticResource HiddenWhenNotSelectedStyle}"> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Button Grid.Row="0">ClickIt</Button> </Grid> </Grid> </DataTemplate> The second row of the outer grid has a style applied which looks like this. The purpose of the style is to : <Style TargetType="{x:Type Grid}" x:Key="HiddenWhenNotSelectedStyle" > <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem} } }" Value="False"> <Setter Property="Grid.Visibility" Value="Collapsed" /> </DataTrigger> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem} } }" Value="True"> <Setter Property="Grid.Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> The ListView renders like this: The desired appearance is this, when none of the elements are selected: ...with, of course, the ListView's height adjusting to accommodate the additional content when the second grid is made visible by selection. What can I do to get the desired behavior?

    Read the article

  • Set ContentTemplate in CodeBehind: XamlParseException 2260 Error

    - by user362215
    Hi, I'd like to change the ContentTemplate of a ContentPresenter in the CodeBehind file. But if I run the Silverlight 4 application a XamlParseException with the error code 2260 occures. foreach (ContentPresenter item in Headers) { item.ContentTemplate = Parent.UnselectedHeaderTemplate; } if ((index >= 0) && (index < Headers.Count)) { ContentPresenter item0 = (ContentPresenter)Headers[index]; item0.ContentTemplate = Parent.SelectedHeaderTemplate; } If I do only the foreach code without the code in the "if", it works. And if I only do the code in the "if" without the foreach it works too. But togheter (the "if"-code and the foreach-code) it doesn't work. I have no idea why it doesn't work. The two templates look like this: <Setter Property="UnselectedHeaderTemplate"> <Setter.Value> <DataTemplate> <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="10,-10" FontSize="72" Foreground="#FF999999" CacheMode="BitmapCache"/> </DataTemplate> </Setter.Value> </Setter> <!-- SelectedHeader template --> <Setter Property="SelectedHeaderTemplate"> <Setter.Value> <DataTemplate> <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="10,-10" FontSize="72" Foreground="{TemplateBinding Foreground}" CacheMode="BitmapCache"/> </DataTemplate> </Setter.Value> </Setter> If you have an idea what problem is please tell me.

    Read the article

  • I have a WPF/Silverlight ListView whose height is unpredictable and too high. How do I control it be

    - by Rob Perkins
    I have a ListView element with a DataTemplate for each ListViewItem defined as follows. When run, the ListView's height is not collapsed onto the items in the view, which is undesirable behavior: <DataTemplate x:Key="LicenseItemTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding company}"></TextBlock> <Grid Grid.Row="1" Style="{StaticResource HiddenWhenNotSelectedStyle}"> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Button Grid.Row="0">ClickIt</Button> </Grid> </Grid> </DataTemplate> The second row of the outer grid has a style applied which looks like this. The purpose of the style is to : <Style TargetType="{x:Type Grid}" x:Key="HiddenWhenNotSelectedStyle" > <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem} } }" Value="False"> <Setter Property="Grid.Visibility" Value="Collapsed" /> </DataTrigger> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem} } }" Value="True"> <Setter Property="Grid.Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> The ListView renders like this: The desired appearance is this, when none of the elements are selected: ...with, of course, the ListView's height adjusting to accommodate the additional content when the second grid is made visible by selection. What can I do to get the desired behavior?

    Read the article

  • How to define a default tooltip style for all Controls

    - by skjagini
    I would like to define a style with a template when there are validation errors and would display the first error message as a tooltip. It works fine when targeting specific control like DatePicker in the following xaml. <Style TargetType="{x:Type ToolKit:DatePicker}"> <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> I cannot get it to work for Control though, i.e. the following doesn't give any tooltip <Style TargetType="{x:Type ToolKit:Control}"> <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> Any idea?

    Read the article

  • WPF binding Ancestor

    - by JerryVienna
    Hi Experts, I have problems with bindings. I want to use a UserControl (Intellibox from codeplex) but I only get error messages in the output window. Basically I have window grid ... stuff ... usercontrol (self written) ... stuff ... usercontrol (IntelliBox) In the Output window I get following stuff: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''. BindingExpression:Path=ShowResults; DataItem=null; target element is 'Popup' (Name='IntelliboxPopup1'); target property is 'IsOpen' (type 'Boolean') The binding in the IntelliBox control is defined as follows: {Binding Path=ShowResults, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}} I guess there is a problem, cause the nesting withing usercontrols - how to I get this error fixed? Thanks!

    Read the article

  • WPF Styles and Tooltips Question

    - by A.R.
    I have a style that I am using to make dynamic tooltips on certain text boxes like so. <Style TargetType="{x:Type TextBox}"> <Setter Property="MinWidth" Value="100"/> <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <!-- item of interest --> <Setter Property="ToolTip"> <Setter.Value> <MultiBinding Converter="{StaticResource ErrorMessageConverter}"> <Binding RelativeSource="{RelativeSource Self}" Path="Tag"/> </MultiBinding> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> This works very well, but if I want to use a more complex tooltip I can't figure out how to bind to 'Tag' anymore for the converter value. For example; ... <Setter Property="ToolTip"> <Setter.Value> <StackPanel> <TextBlock> <TextBlock.Text> <MultiBinding Converter="{StaticResource ErrorMessageConverter}"> <!-- item of interest --> <Binding RelativeSource=" what goes here?? "/> </MultiBinding> </TextBlock.Text> </TextBlock> <Image/> </StackPanel> </Setter.Value> </Setter> ... I have tried several flavors of 'FindAncestor' and what not for the relative source, but I can't get anything to work. Any ideas?? UPDATE: 12-29-2010 : Here is the correct code, answer provided by our friend Goblin below. Works perfectly! ... <Setter Property="ToolTip"> <Setter.Value> <!-- Item of interest --> <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}"> <StackPanel> <Image/> <TextBlock> <TextBlock.Text> <MultiBinding Converter="{StaticResource ErrorMessageConverter}"> <Binding Path="Tag"/> </MultiBinding> </TextBlock.Text> </TextBlock> </StackPanel> </ToolTip> </Setter.Value> </Setter> ...

    Read the article

  • TreeViewItem - Use ControlTemplate and HierarchicalDataTemplate together

    - by CrownJ
    I'm using HierarchicalDataTemplate in my TreeView, and I wanted to also overwrite the default template for the TreeViewItem so that when an item is selected, it only highlights the text, not including the icon next to it. <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Children}"> <TreeViewItem Style="{StaticResource TreeViewItemStyle}" Header="{Binding DisplayText}" /> </HierarchicalDataTemplate> </TreeView.ItemTemplate> <TreeView.Resources> <Style x:Key="TreeViewItemFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}"> <Setter Property="Focusable" Value="False"/> <Setter Property="Width" Value="19"/> <Setter Property="Height" Value="13"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Border Width="19" Height="13" Background="Transparent"> <Border Width="9" Height="9" SnapsToDevicePixels="true" BorderBrush="#FF7898B5" BorderThickness="1" CornerRadius="1"> <Border.Background> <LinearGradientBrush EndPoint="1,1" StartPoint="0,0"> <GradientStop Color="White" Offset=".2"/> <GradientStop Color="#FFC0B7A6" Offset="1"/> </LinearGradientBrush> </Border.Background> <Path x:Name="ExpandPath" Fill="Black" Margin="1,1,1,1" Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"/> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="Data" TargetName="ExpandPath" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="1,0,0,0"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TreeViewItem}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/> <StackPanel Orientation="Horizontal" Grid.Column="1" > <Image Width="16" Height="16" Margin="3,0" Source="{Binding Path=ImageSource}" /> <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="0" Padding="0"> <ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/> </Border> </StackPanel> <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="false"> <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/> </Trigger> <Trigger Property="HasItems" Value="false"> <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/> </Trigger> <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Control.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Control.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <VirtualizingStackPanel/> </ItemsPanelTemplate> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </TreeView.Resources> I couldn't find a way to use both the HierarchicalDataTemplate and ControlTemplate together so I can specify the ItemsSource and also change parts of the control's behavior. When I do the above code, it won't select the treeviewitem at all.

    Read the article

  • WPF binding only inside XAML (simple question)

    - by 0xDEAD BEEF
    Why this works <myToolTip:UserControl1> <TextBlock Text="{Binding Path=TestString, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type myToolTip:UserControl1}}}"/> </myToolTip:UserControl1> BUT this does not <myToolTip:UserControl1 x:Name="userControl"> <TextBlock Text="{Binding Path=TestString, ElementName=userControl}"/> </myToolTip:UserControl1> and is there realy no shorter (faster) fay, to acces usercontrols elements?! Sincerely, 0xDEAD BEEF

    Read the article

  • WPF C# how to create THIS binding in code?

    - by 0xDEAD BEEF
    I wonder, how to create this binding, since Line.X2 IS NOT dependency property! :( <Line Y1="0" X1="0" Y2="0" Stroke="Blue" StrokeThickness="3" Margin="0 -2 0 -2" X2="{Binding Path=RenderSize.Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}}"/>

    Read the article

  • DependencyProperty binding not happening on initial load

    - by Ari Roth
    I'm trying to do something simple -- make a DependencyProperty and then bind to it. However, the getter doesn't appear to fire when I start up the app. (I'm guessing the solution will make me smack my head and go "Doh!", but still. :) ) Any ideas? Code-behind code: public static readonly DependencyProperty PriorityProperty = DependencyProperty.Register("Priority", typeof (Priority), typeof (PriorityControl), null); public Priority Priority { get { return (Priority)GetValue(PriorityProperty); } set { SetValue(PriorityProperty, value); } } Control XAML: <ListBox Background="Transparent" BorderThickness="0" ItemsSource="{Binding Path=Priorities}" Name="PriorityList" SelectedItem="{Binding Path=Priority, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <Grid Height="16" Width="16"> <Border BorderBrush="Black" BorderThickness="2" CornerRadius="3" Visibility="{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected, Converter={StaticResource boolToVisibilityConverter}}" /> <Border CornerRadius="3" Height="12" Width="12"> <Border.Background> <SolidColorBrush Color="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=Content, Converter={StaticResource priorityToColorConverter}}" /> </Border.Background> </Border> </Grid> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> Binding statement: <UI:PriorityControl Grid.Column="8" Priority="{Binding Path=Priority}" VerticalAlignment="Center"/> Some other notes: Binding is in a UserControl UserControl contains the PriorityControl PriorityControl contains the DependencyProperty I've checked that the data the UserControl is getting the appropriate data -- every other binding works. If I change the selection on the PriorityControl via the mouse, everything fires as appropriate. It's just that initial setting of the value that isn't working. Priority is an enum.

    Read the article

  • WPF TreeView: How to style selected items with rounded corners like in Explorer

    - by Helge Klein
    The selected item in a WPF TreeView has a dark blue background with "sharp" corners. That looks a bit dated today: I would like to change the background to look like in Explorer of Windows 7 (with/without focus): What I tried so far does not remove the original dark blue background but paints a rounded border on top of it so that you see the dark blue color at the edges and at the left side - ugly. Interestingly, when my version does not have the focus, it looks pretty OK: I would like to refrain from redefining the control template as shown here or here. I want to set the minimum required properties to make the selected item look like in Explorer. Alternative: I would also be happy to have the focused selected item look like mine does now when it does not have the focus. When losing the focus, the color should change from blue to grey. Here is my code: <TreeView x:Name="TreeView" ItemsSource="{Binding TopLevelNodes}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="BorderBrush" Value="#FF7DA2CE" /> <Setter Property="Background" Value="#FFCCE2FC" /> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type viewmodels:ObjectBaseViewModel}" ItemsSource="{Binding Children}"> <Border Name="ItemBorder" CornerRadius="2" Background="{Binding Background, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" BorderThickness="1"> <StackPanel Orientation="Horizontal" Margin="2"> <Image Name="icon" Source="/ExplorerTreeView/Images/folder.png"/> <TextBlock Text="{Binding Name}"/> </StackPanel> </Border> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView>

    Read the article

  • DataTrigger with Value Binding

    - by plotnick
    Why this doesn't work? <Style x:Key="ItemContStyle" TargetType="{x:Type ListViewItem}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Asset}" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=CurrentAsset}"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers>

    Read the article

  • 'Auto' value in binding property 'width'

    - by Ivan
    Must attach to the property Width, what I'm doing this: <ColumnDefinition Width="{Binding Path=TabPanelWidth, RelativeSource={RelativeSource TemplatedParent}}" /> - public float TabPanelWidth { get {return (float) GetValue (TabPanelWidthProperty);} set {SetValue (TabPanelWidthProperty, value);} } public static readonly DependencyProperty TabPanelWidthProperty = DependencyProperty.Register ("TabPanelWidth", typeof (float), typeof (BivTabControl), new UIPropertyMetadata (null)); But vozmozhnast need to set not only fixed values, but still a value of type: Auto, 0.5 *, and the like. Any ideas?

    Read the article

  • WPF ControlTemplate and Binding

    - by Vinjamuri
    In the below code, MousePressImage is a dependency property of class ButtonControl. The following Binding doesn't work.. Appreciate your help in solving this issue.. Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=MousePressImage}"/> -- I create the ButtonControl like this. <local:ButtonControl Height="48" Width="160" MouseOverImage="pack://application:,,,/Recipe_06_13;component/Resources/Over.bmp" MousePressImage="pack://application:,,,/Recipe_06_13;component/Resources/Press.bmp" DisableImage=" "> </local:ButtonControl>

    Read the article

  • Unset/Change Binding in WPF

    - by captcalamares
    How can I unset the binding applied to an object so that I can apply another binding to it from a different location? Suppose I have two data templates binded to the same object reference. Data Template #1 is the default template to be loaded. I try to bind a button command to a Function1 from my DataContext class: <Button Content="Button 1" CommandParameter="{Binding }" Command="{Binding DataContext.Function1, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/> This actually works and the function gets binded. However, when I try to load Data Template # 2 to the same object (while trying to bind another button command to a different function (Function2) from my DataContext class): <Button Content="Button 2" CommandParameter="{Binding }" Command="{Binding DataContext.Function2, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" /> It doesn't work and the first binding is still the one executed. Is there a workaround to this? EDIT (for better problem context): I defined my templates in my Window.Resources: <Window.Resources> <DataTemplate DataType="{x:Type local:ViewModel1}"> <local:View1 /> </DataTemplate> <DataTemplate DataType="{x:Type local:ViewModel2}"> <local:View2 /> </DataTemplate> </Window.Resources> The View1.xaml and the View2.xaml contain the button definitions that I described above (I want them to command the control of my process flow). ViewModel1 and ViewModel2 are my ViewModels that implement the interface IPageViewModel which is the type of my variable CurrentPageViewModel. In my XAML, I binded ContentControl to the variable CurrentPageViewModel: <ContentControl Content="{Binding CurrentPageViewModel}" HorizontalAlignment="Center"/> In my .CS, I have a list defined as List<IPageViewModel> PageViewModels, which I use to contain the instances of my two View Models: PageViewModels.Add(new ViewModel1()); PageViewModels.Add(new ViewModel2()); // Set starting page CurrentPageViewModel = PageViewModels[0]; When I try to change my CurrentPageViewModel to the other view model, this is when I want the new binding to work. Unfortunately, it doesn't. Am I doing things the right way?

    Read the article

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