Search Results

Search found 68 results on 3 pages for 'findancestor'.

Page 1/3 | 1 2 3  | Next Page >

  • WPF RelativeSource FindAncestor doesn't work outside of the Control.Resources context?

    - by sker
    I have this VisualBrush resource I took from some site and I apply it with triggers to a TextBox. <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left"> <VisualBrush.Visual> <TextBlock FontStyle="Italic" Text="{Binding Path=Tag, RelativeSource={RelativeSource AncestorType={x:Type Control}, AncestorLevel=1}}"/> </VisualBrush.Visual> </VisualBrush> <Style x:Key="DefaultText" TargetType="TextBox"> <Style.Triggers> <Trigger Property="Text" Value="{x:Null}"> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> <Trigger Property="Text" Value=""> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> </Style.Triggers> </Style> If I place both the VisualBrush and the Style inside the TextBox.Resources tag in XAML, it works fine. But if I take it out and place it in the Window.Resources or a merged dictionary, it stops working. The problem is the Binding, it doesn't find the ancestor TextBox for some reason. I already tried removing AncestorLevel and using AncestorType={x:Type TextBox} - it doesn't work. Any ideas?

    Read the article

  • intercept RelativeSource FindAncestor

    - by Pradeep
    I have a WPF application which runs as a excel plugin, it has its visual tree like so Excel ElementHost WPF UserControl WPF ribbon bar control Now any controls sitting on the WPF ribbon bar control are not enabled when the plugin is loaded within excel. See error below System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Window', AncestorLevel='1''. BindingExpression:Path=IsActive; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object') If I nest the ribbon bar control in a standalone Window(outside excel) it works fine. Is there a way to intercept the FindAncestor call for a Window and wire it to something else.? Note that I cannot change the above binding as it isn't my control.

    Read the article

  • Alternative to FindAncestor RelativeSource in Silverlight 4 to bind to a property of the page

    - by TimothyP
    Hi, FindAncestor RelativeSource only supports 'Self' and 'TemplatedParent', but I have to bind the width of a popup to the width of the page. Giving the page a name causes problems because sometimes it will throw exceptions saying a control with that name is already present in the visual tree. <Popup IsOpen="True" Width="{Binding ElementName=BordPage, Path=Width}" Height="{Binding ElementName=BordPage, Path=Height}"> Background information: I'm using a SL4 navigation based application here. BordPage is a navigation page, which I'm using multiple times within the application. So giving it a name in the page itself is not really a good idea, but I don't know how else I can bind to the width and height of the page. What I'm trying to do is have a black border (with opacity 0.8) cover the entire screen, (including the controls of the MainPage). Then on top of that I want to display some other controls. Since the application is touch controlled, providing the user with a ComboBox to select a value doesn't really work wel. Instead I want to show this black overlay window with a listbox taking up most of the screen so the user can simply touch the value he wants with a single click. Update: I just realized I can use the ChildWindow class to do this. But my original question remains.

    Read the article

  • WPF - simple relative path - FindAncestor

    - by user309392
    In the XAML below the ToolTip correctly binds to RelativeSource Self. However, I can't for the life of me work out how to get the TextBlock in the commented block to refer to SelectedItem.Description <Controls:RadComboBoxWithCommand x:Name="cmbPacking" Grid.Row="2" Grid.Column="5" ItemsSource="{Binding PackingComboSource}" DisplayMemberPath="DisplayMember" SelectedValuePath="SelectedValue" SelectedValue="{Binding ElementName=dataGrid1, Path=SelectedItem.PackingID}" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Description}" IsSynchronizedWithCurrentItem="True" Style="{StaticResource comboBox}"> <!-- <Controls:RadComboBoxWithCommand.ToolTip>--> <!-- <TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Description}" TextWrapping="Wrap" Width="50"/>--> <!-- </Controls:RadComboBoxWithCommand.ToolTip>--> </Controls:RadComboBoxWithCommand> I would appreciate any suggestions Thanks - Jeremy

    Read the article

  • In WPF, how do I get a command in a Control Template to bind to a property in a parent?

    - by Keith
    I am relatively new to WPF and sometimes it makes my head explode. However, I do like the power behind it, especially when used with the MVVM model. I have a control template that contains a button. I use that control template inside of a custom control. I want to add a property on the custom control that will bind to the command property of the button inside the control template. Basically, it is a combo box with a button to the right of it to allow a user to pop up a search dialog. Since this control could appear on a usercontrol multiple times, I need to be able to potentially bind each control to a different command (Searh products, search customers, etc). However, I have been unable to figure out how to do this Here is some sample XAML <Style TargetType="{x:Type m:SelectionFieldControl}"> <Setter Property="LookupTemplate" Value="{StaticResource LookupTemplate}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type m:SelectionFieldControl}"> <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True" Focusable="False"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" MinWidth="0" SharedSizeGroup="{Binding LabelShareSizeGroupName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:BaseFieldControl}}}" /> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="Auto" SharedSizeGroup="{Binding WidgetsShareSizeGroupName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:BaseFieldControl}}}" /> </Grid.ColumnDefinitions> <!-- Customized Value Part --> <ComboBox x:Name="PART_Value" Grid.Column="1" Margin="4,2,0,1" SelectedValue="{Binding Path=SelectionField.Value, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:SelectionFieldControl}}}" IsEnabled="{Binding Field.IsNotReadOnly, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:SelectionFieldControl}}}" Visibility="{Binding Field.IsInEditMode, Converter={StaticResource TrueToVisible}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:SelectionFieldControl}}}" FontFamily="{StaticResource FontFamily_Default}" FontSize="11px"> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling"/> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> <StackPanel Grid.Column="2" Orientation="Horizontal" Name="PART_Extra" Focusable="False"> <ContentControl Name="PART_LookupContent" Template="{Binding LookupTemplate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type m:SelectionFieldControl}}}" Focusable="False"/> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> I thought I could get it to work by doing something like this <Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type SelectionFieldControl}}, Path=ShowSearchCommand}" Margin="2" /> but it does not work. Any help would be greatly appreciated.

    Read the article

  • DynamicResource and Dynamic Items in ContextMenu on XamDataGrid

    - by miguel
    I would like to dynamically create a set of context menu options based upon some properties. Currently, I am creating a context menu as a DynamicResource with the visibility of the menu options bound to the properties, however, it seems that the DynamicResource is created only once, at runtime. Is this true? What I would like to do is have the menu generated each time, which will take into account the property changes on the data object. Please see the following XAML snippet: <Border DockPanel.Dock="Right" Margin="4,4,4,4" BorderBrush="Gray" BorderThickness="1" CornerRadius="3" > <igDP:XamDataGrid Height="Auto" Width="Auto" Style="{DynamicResource DefaultInfragisticsGridStyle}" Name="axeDataGrid" ActiveRecord="{Binding Path=SelectedItem, Mode=TwoWay}" DataSource="{Binding Path=Axes}" ContextMenuOpening="ContextMenuOpeningHandler"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordPresenter}" BasedOn="{x:Static Themes:DataPresenterAero.DataRecordPresenter}"/> <ContextMenu x:Key="RecordContextMenu"> <ContextMenu.Resources> <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/> </ContextMenu.Resources> <MenuItem Header="Cancel Axe" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.CancelAxe}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.IsCancelAxeAllowed, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"/> <MenuItem Header="Create RFQ" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.CreateRFQ}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.IsCreateRfqAllowed, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"/> </ContextMenu> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="ContextMenu" Value="{DynamicResource RecordContextMenu}" /> </Style>

    Read the article

  • MVVM Listbox DataTemplate SelectedItem

    - by StinkerPeter
    I am using a ListBox with a DataTemplate as shown below (xaml simplified and variable names changed). <ListBox ItemsSource="{Binding Path=ObservCollectionItems}" SelectedItem="{Binding Path=SelectedItemVar, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding SomeVar}" /> <Border> <StackPanel> <Button Content="String1" Command="{Binding DataContext.Command1} RelativeSource={RelativeSource FindAncestor, ListBox, 1}}" /> <Button Content="String2" Command="{Binding DataContext.Command2} RelativeSource={RelativeSource FindAncestor, ListBox, 1}}" /> </StackPanel> </Border> </StackPanel> </DataTemplate> <ListBox.ItemTemplate> </ListBox> I need the SelectedItemVar (dependency property) to update when I click on one of the buttons. SelectedItemVar is then used for the respective button's command. SelectedItemVar does update when I click on the TextBlock or the Border, but not when I click either button. I found a non-MVVM solution to this problem here. I do not want to add code in the file-behind to solve this, as they did in the link. Is there a clean solution that can be done in XAML. Beyond the non-MVVM solutions, I have not found anyone with this problem. I would have thought this was fairly common. Finally, I found this Command="{Binding DataContext.CommandName} RelativeSource={RelativeSource FindAncestor, ListBox, 1} for the Command binding. I do not fully understand what it is doing, but I do know that the command wasn't firing when I was binding directly to CommandName.

    Read the article

  • Multibinding File-Paths into a Button ControlTemplate

    - by Bill
    I am trying to develop an application that uses a number of images that are stored in a seperate remote file location. The file-paths to the UI elements are stored within the Application Settings. Although I understand how to access the images from Applications Settings using a MultiBinding and a value converter, I'm not sure how to integrate the Multibinding into the ImageButton ControlTemplate below. Can anyone steer me in the right direction? <Image.Source> <MultiBinding Converter="{StaticResource MyConverter}"> <Binding Source="{StaticResource Properties.Settings}" Path="Default.pathToInterfaceImages" /> <Binding Source="ScreenSaver.png"></Binding> </MultiBinding> </Image.Source> <Button Click="btn_ScreenSaver_Click" Style="{DynamicResource ThreeImageButton}" local:ThreeImageButton.Image="C:\Skins\ScreenSaver_UP.png" local:ThreeImageButton.MouseOverImage="C:\Skins\ScreenSaver_OVER.png" local:ThreeImageButton.PressedImage="C:\Skins\ScreenSaver_DOWN.png"/> <Style x:Key="ThreeImageButton" TargetType="{x:Type Button}"> <Setter Property="FontSize" Value="10"/> <Setter Property="Height" Value="34"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <StackPanel Orientation="Horizontal" > <Image Name="PART_Image" Source= "{Binding Path=(local:ThreeImageButton.Image), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" /> </StackPanel> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Source" Value="{Binding Path=(local:ThreeImageButton.MouseOverImage), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" TargetName="PART_Image"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Source" Value="{Binding Path=(local:ThreeImageButton.PressedImage), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" TargetName="PART_Image"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Source" Value="{Binding Path=(local:ThreeImageButton.Image), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" TargetName="PART_Image"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> public class ThreeImageButton : DependencyObject { // Add three new Dependency Properties to the Button Class to hold the // path to each of the images that are bound to the control, displayed // during normal, mouse-over and pressed states. public static readonly DependencyProperty ImageProperty; public static readonly DependencyProperty MouseOverImageProperty; public static readonly DependencyProperty PressedImageProperty; public static ImageSource GetImage(DependencyObject obj) { return (ImageSource)obj.GetValue(ImageProperty); } public static ImageSource GetMouseOverImage(DependencyObject obj) { return (ImageSource)obj.GetValue(MouseOverImageProperty); } public static ImageSource GetPressedImage(DependencyObject obj) { return (ImageSource)obj.GetValue(PressedImageProperty); } public static void SetImage(DependencyObject obj, ImageSource value) { obj.SetValue(ImageProperty, value); } public static void SetMouseOverImage(DependencyObject obj, ImageSource value) { obj.SetValue(MouseOverImageProperty, value); } public static void SetPressedImage(DependencyObject obj, ImageSource value) { obj.SetValue(PressedImageProperty, value); } // Register each property with the control. static ThreeImageButton() { var metadata = new FrameworkPropertyMetadata((ImageSource)null); ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ThreeImageButton), metadata); var metadata1 = new FrameworkPropertyMetadata((ImageSource)null); MouseOverImageProperty = DependencyProperty.RegisterAttached("MouseOverImage", typeof(ImageSource), typeof(ThreeImageButton), metadata1); var metadata2 = new FrameworkPropertyMetadata((ImageSource)null); PressedImageProperty = DependencyProperty.RegisterAttached("PressedImage", typeof(ImageSource), typeof(ThreeImageButton), metadata2); } }

    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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • Where do I define dependency properties shared by the detail views in a master-detail MVVM WPF scena

    - by absence
    I can think of two ways to implement dependency properties that are shared between the detail views: Store them in the master view model and add data bindings to the detail view models when they are created, and bind to them in the detail view. Don't store them in the view models at all, and use FindAncestor to bind directly to properties of the master view instead. What are the pros and cons of each, and are there other/better options?

    Read the article

  • How do I get the ListBox from a ListBoxItem?

    - by Shimmy
    Sub FindAncestor(Of TParent, reference As DependencyObject) As TParent 'find the parent ListBox container End Sub 'Usage Sub Handle(lbi As ListBoxItem) Dim lb = GetListBox(lbi) End Sub I have a button in a ListBoxItem datatemplate, I want in the handler of the button to access the parent ListBox (this is the way I want to access it, since it's all nested in other DataTemplates, ItemsControls and stuff).

    Read the article

  • Trouble binding command in grid menu item.

    - by Pete
    I have a grid that's inside a usercontrol derived class called MediatedUserControl. I'm adding a context menu to let the user delete an item, but I've been unable to figure out how to bind the command to my command property. I'm using MVVM and my viewmodel implements a public ICommand property called DeleteSelectedItemCommand. However, when the view is displayed, I get the following message in the output window: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='BRO.View.MediatedUserControl', AncestorLevel='1''. BindingExpression:Path=DataContext.DeleteSelectedItemCommand; DataItem=null; target element is 'BarButtonItem' (HashCode=6860584); target property is 'Command' (type 'ICommand') I feel like I generally have a good handle on bindings like this and can't figure out what it is I'm missing here. Thanks for any help you can provide. <dxg:GridControl HorizontalAlignment="Left" Margin="12,88,0,0" x:Name="gridControl1" VerticalAlignment="Top" Height="500" Width="517" DataSource="{Binding ItemList}" BorderBrush="{StaticResource {x:Static SystemColors.ActiveBorderBrushKey}}" ShowBorder="True" Background="{StaticResource {x:Static SystemColors.ControlLightBrushKey}}" UseLayoutRounding="False" DataContext="{Binding}"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Code" Header="Code" Width="107" /> <dxg:GridColumn FieldName="Name" Header="Item" Width="173" /> <dxg:GridColumn FieldName="PricePerItem" Header="Unit Price" Width="70"> <dxg:GridColumn.EditSettings> <dxe:TextEditSettings DisplayFormat="N2" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> <dxg:GridColumn FieldName="Quantity" Header="Qty" Width="50" AllowEditing="True" /> <dxg:GridColumn FieldName="TotalPrice" Header="Total Price" Width="90"> <dxg:GridColumn.EditSettings> <dxe:TextEditSettings DisplayFormat="N2" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView ShowIndicator="False" ShowGroupPanel="False" MultiSelectMode="Row" AllowColumnFiltering="False" AllowBestFit="False" AllowFilterEditor="False" AllowEditing="False" AllowGrouping="False" AllowSorting="False" AllowResizing="False" AllowMoving="False" AllowMoveColumnToDropArea="False" AllowDateTimeGroupIntervalMenu="False" > <dxg:TableView.RowCellMenuCustomizations> <dxb:BarButtonItem Name="deleteRowItem" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:MediatedUserControl, AncestorLevel=1}, Path=DataContext.DeleteSelectedItemCommand}"> </dxb:BarButtonItem> </dxg:TableView.RowCellMenuCustomizations> </dxg:TableView> </dxg:GridControl.View>

    Read the article

  • WPF Binding with RelativeSource of Window Requires "DataContext" in Path?

    - by Phil Sandler
    The following code works, but I'm curious as to why I need the Path to be prefixed with "DataContext"? In most other cases, the path used is relative to DataContext. Is it because I am using a RelativeSource? Because the source is at the root level (Window)? <Style TargetType="TextBox"> <Setter Property="IsReadOnly" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.IsReadOnly}"/> </Style>

    Read the article

  • WPF DataGrid Hide RowDetails or Unselect Row

    - by Nate Zaugg
    I have a DataGrid who's RowDetails is set to show when selected (RowDetailsVisibilityMode="VisibleWhenSelected"). Now I want to be able to get rid of it! I put a close button on the row details with this code: private void Button_Click(object sender, RoutedEventArgs e) { e.Handled = true; Button button = sender as Button; DataGridRow row = button.FindAncestor(); row.DetailsVisibility = Visibility.Collapsed; } That code gets me 90% there, but once the row details is collapsed for a given row it will not appear the next time that row is selected.

    Read the article

  • How to set a binding in WPF Toolkit Datagrid's ContextMenu CommandParameter

    - by Boris Lipschitz
    I need to create a ContextMenu where I want to pass a currently selected index of the datagrid to a ViewModel using CommandParameter. The following Xaml code doesn't work. What might be the problem? <dg:DataGrid ItemsSource="{Binding MarketsRows}" <dg:DataGrid.ContextMenu > <ContextMenu > <MenuItem Header="Add Divider" CommandParameter="{Binding Path=SelectedIndex, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGrid}}}" Command="{Binding Path= AddDividerCommand}"/> </ContextMenu> </dg:DataGrid.ContextMenu> </dg:DataGrid>

    Read the article

  • WPF DataTemplate Trigger set a property in a different DataTemplate

    - by Burt
    I have 2 DataTemplates (A & B). A contains an expander and the expander's HeaderTemplate is pointed at another DataTemplate (B). DataTemplate B is shown below: <DataTemplate x:Key="ProjectExpanderHeader"> <Border CornerRadius="2,2,0,0" Background="{StaticResource ItemGradient}" HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}, Mode=OneWayToSource}"> <local:ItemContentsUserControl Height="30"/> </Border> </DataTemplate> Is it possible to set the CornerRadius of B's Border when the IsExpanded property of A's Expander is set to true? Thanks in advance.

    Read the article

1 2 3  | Next Page >