Search Results

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

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

  • Assign enum property in xaml using silverlight

    - by Malcolm
    I have a property of datattype enum : like public BreakLevel Level { get { return level; } set { level = value; } } And enum defined : public enum BreakLevel { Warning, Fatal } I want bind the neum property to the visibility of my border , somewhat like this: Visibility="{Binding BreakLevel.Fatal}" so is it possible? <Border CornerRadius="4" BorderThickness="1" BorderBrush="#DAE0E5" Visibility="{Binding DataContext.IsError, Converter={StaticResource BoolToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" >

    Read the article

  • Binding one dependency property to another

    - by Gregory Dodd
    I have a custom Tab Control that I have created, but I am having an issue. I have an Editable TextBox as part of the custom TabControl View. <Controls:EditableTextControl x:Name="PageTypeName" Style="{StaticResource ResourceKey={x:Type Controls:EditableTextControl}}" Grid.Row="0" TabIndex="0" Uid="0" AutomationProperties.AutomationId="PageTypeNameTextBox" AutomationProperties.Name="PageTypeName" Visibility="{Binding ElementName=PageTabControl,Path=ShowPageType}"> <Controls:EditableTextControl.ContextMenu> <ContextMenu x:Name="TabContextMenu"> <MenuItem Header="Rename Page Type" Command="{Binding Path=PlacementTarget.EnterEditMode, RelativeSource={RelativeSource AncestorType=ContextMenu}}" AutomationProperties.AutomationId="RenamePageTypeMenuItem" AutomationProperties.Name="RenamePageType"/> <MenuItem Header="Delete Page Type" Command="{Binding Path=PageTypeDeletedCommand}" AutomationProperties.AutomationId="DeletePageTypeMenuItem" AutomationProperties.Name="DeletePageType"/> </ContextMenu> </Controls:EditableTextControl.ContextMenu> <Controls:EditableTextControl.Content> <!--<Binding Path="CurrentPageTypeViewModel.Name" Mode="TwoWay"/>--> <Binding ElementName="PageTabControl" Path="CurrentPageTypeName" Mode ="TwoWay"/> </Controls:EditableTextControl.Content> </Controls:EditableTextControl> In the Content section I am binding to a Dependency Prop called CurrentPageTypeName. This Depedency prop is part of this custom Tab Control. public static DependencyProperty CurrentPageTypeNameProperty = DependencyProperty.Register("CurrentPageTypeName", typeof(object), typeof(TabControlView)); public object CurrentPageTypeName { get { return GetValue(CurrentPageTypeNameProperty) as object; } set { SetValue(CurrentPageTypeNameProperty, value); } } In another view, where I am using the custom TabControl I then bind my property, with the actual name value, to CurrentPageTypeName property as seen below: <Views:TabControlView Grid.Row="0" Name="RunPageTabControl" TabItemsSource="{Binding RunPageTypeViewModels}" SelectedTab="{Binding Converter={StaticResource debugConverter}}" CurrentPageTypeName="{Binding Path=RunPageName, Mode=TwoWay}" TabContentTemplateSelector="{StaticResource tabItemTemplateSelector}" SelectedIndex="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedTabIndex}" ShowPageType="Hidden" > <!--<Views:TabControlView.TabContentTemplate> <DataTemplate DataType="{x:Type ViewModels:RunPageTypeViewModel}"> <RunViews:RunPageTypeView/> </DataTemplate> </Views:TabControlView.TabContentTemplate>--> </Views:TabControlView> My problem is that nothing seems to be happening. It is grabbing its Content from the Itemsource, and not from my chained Dependency props. Is what I am trying even possible? If so, what have I done wrong. Thanks for looking.

    Read the article

  • WPF Templates error - "Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw

    - by jasonk
    I've just started experimenting with WPF templates vs. styles and I'm not sure what I'm doing wrong. The goal below is to alternate the colors of the options in the menu. The code works fine with just the , but when I copy and paste/rename it for the second segment of "MenuChoiceOdd" I get the following error: Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception. Sample of the code: <Window x:Class="WpfApplication1.Template_Testing" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Template_Testing" Height="300" Width="300"> <Grid> <Grid.Resources> <ControlTemplate x:Key="MenuChoiceEven"> <Border BorderThickness="1" BorderBrush="#FF4A5D80"> <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="0" Width="Auto" FontSize="14" Foreground="SlateGray" TextAlignment="Left" AllowDrop="True" Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"> <TextBlock.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White" Offset="0" /> <GradientStop Color="#FFC2CCDB" Offset="1" /> </LinearGradientBrush> </TextBlock.Background> </TextBlock> </Border> </ControlTemplate> <ControlTemplate x:Key="MenuChoiceOdd"> <Border BorderThickness="1" BorderBrush="#FF4A5D80"> <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="0" Width="Auto" FontSize="14" Foreground="SlateGray" TextAlignment="Left" AllowDrop="True" Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"> <TextBlock.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White" Offset="0" /> <GradientStop Color="##FFCBCBCB" Offset="1" /> </LinearGradientBrush> </TextBlock.Background> </TextBlock> </Border> </ControlTemplate> </Grid.Resources> <Border BorderBrush="SlateGray" BorderThickness="2" Margin="10" CornerRadius="10" Background="LightSteelBlue" Width="200"> <StackPanel Margin="4"> <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="2,2,2,0" Name="MenuHeaderTextBlock" Text="TextBlock" Width="Auto" FontSize="16" Foreground="PaleGoldenrod" TextAlignment="Left" Padding="10" FontWeight="Bold"><TextBlock.Background><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="LightSlateGray" Offset="0" /><GradientStop Color="DarkSlateGray" Offset="1" /></LinearGradientBrush></TextBlock.Background></TextBlock> <StackPanel Height="Auto" HorizontalAlignment="Stretch" Margin="2,0,2,0" Name="MenuChoicesStackPanel" VerticalAlignment="Top" Width="Auto"> <Button Template="{StaticResource MenuChoiceEven}" Content="Test Even menu element" /> <Button Template="{StaticResource MenuChoiceOdd}" Content="Test odd menu element" /> </StackPanel> </StackPanel> </Border> </Grid> </Window> What am I doing wrong?

    Read the article

  • Why does WPF Style to show validation errors in ToolTip work for a TextBox but fails for a ComboBox?

    - by Mike B
    I am using a typical Style to display validation errors as a tooltip from IErrorDataInfo for a textbox as shown below and it works fine. <Style TargetType="{x:Type 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> But when i try to do the same thing for a ComboBox like this it fails <Style TargetType="{x:Type ComboBox}"> <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> The error I get in the output window is: System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'ValidationError') from '(Validation.Errors)' (type 'ReadOnlyObservableCollection`1'). BindingExpression:Path=(0)[0].ErrorContent; DataItem='ComboBox' (Name='ownerComboBox'); target element is 'ComboBox' (Name='ownerComboBox'); target property is 'ToolTip' (type 'Object') ArgumentOutOfRangeException:'System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.Parameter name: index' Oddly it also attempts to make invalid Database changes when I close the window if I change any ComboBox values (This is also when the binding error occurs)!!! Cannot insert the value NULL into column 'EmpFirstName', table 'OITaskManager.dbo.Employees'; column does not allow nulls. INSERT fails. The statement has been terminated. Simply by commenting the style out everyting works perfectly. How do I fix this? Just in case anyone needs it one of the comboBox' xaml follows: <ComboBox ItemsSource="{Binding Path=Employees}" SelectedValuePath="EmpID" SelectedValue="{Binding Path=SelectedIssue.Employee2.EmpID, Mode=OneWay, ValidatesOnDataErrors=True}" ItemTemplate="{StaticResource LastNameFirstComboBoxTemplate}" Height="28" Name="ownerComboBox" Width="120" Margin="2" SelectionChanged="ownerComboBox_SelectionChanged" /> <DataTemplate x:Key="LastNameFirstComboBoxTemplate"> <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}{1}, {0}" > <Binding Path="EmpFirstName" /> <Binding Path="EmpLastName" /> </MultiBinding> </TextBlock.Text> </TextBlock> </DataTemplate> SelectionChanged: (I do plan to implement commanding before long but, as this is my first WPF project I have not gone full MVVM yet. I am trying to take things in small-medium sized bites) // This is done this way to maintain the DataContext Integrity // and avoid an error due to an Object being "Not New" in Linq-to-SQL private void ownerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Employee currentEmpl = ownerComboBox.SelectedItem as Employee; if (currentEmpl != null && currentEmpl != statusBoardViewModel.SelectedIssue.Employee2) { statusBoardViewModel.SelectedIssue.Employee2 = currentEmpl; } }

    Read the article

  • WPF Navigation Page Breadcrumb

    - by Ryan
    I found code to use a breadcrumb instead of the navigation buttons for my pages. This code works perfect with setting a page as the startup. My problem is that I need to have a window with a frame control as the startup and this is causing the breadcrumb to not show at all. I seem to be missing something with my styling. The types used to be NavigationWindow but I changed them to Frame to try and get a working solution. <Style TargetType="Frame" x:Key="{x:Type Frame}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Frame"> <Grid Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="50"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Frame}}, Path=BackStack}"> <!--Force the ItemsContol to use a wrap panel as Items host--> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <local:InverseWrapPanel KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Cycle"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Command="NavigationCommands.NavigateJournal" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Content="{Binding Name}"> <Button.Template> <ControlTemplate TargetType="Button"> <WrapPanel> <TextBlock Name="text1" FontWeight="Bold" Text="{TemplateBinding Content}"/> <TextBlock Name="text2" FontWeight="Bold" Text=">>" Margin="2,0,0,0"/> </WrapPanel> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="text1" Property="Foreground" Value="Blue"/> <Setter TargetName="text2" Property="Foreground" Value="Blue"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <AdornerDecorator Grid.Row="2"> <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/> </AdornerDecorator> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

    Read the article

  • CommandBinding broken in inner Custom Control when nesting two Custom Controls of the same type.

    - by Fredrik Eriksson
    I've done a Custom Control in form of a GroupBox but with an extra header which purpose is to hold a button or a stackpanel with buttons at the other side. I've added the a Dependency Property to hold the extra header and I've connected the customized template. Everything works fine until I put one of these controls in another one. Now the wierd stuff begins(at least in my eyes xP), the command binding in the inner control simply isn't set. I tried to use Snoop to gather some data, the see if the inherits is broken and when I clicked on the buttons which isn't doing what I want it to, boom, breakpoint triggered. So in some wierd way the Command isn't set until something that I don't know what it is, happens, which snoops triggers. I've also tried to put the buttons in the regular Header property and that works fine, but not with my own made. I could just switch places with them to make it like I want but now I'm curious to know where the problem lies... Now I wonder, what can I've missed? The control class: public class TwoHeaderedGroupBox : GroupBox { static TwoHeaderedGroupBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TwoHeaderedGroupBox), new FrameworkPropertyMetadata(typeof(TwoHeaderedGroupBox))); } public static DependencyProperty HeaderTwoProperty = DependencyProperty.Register("HeaderTwo", typeof(object), typeof(TwoHeaderedGroupBox), new FrameworkPropertyMetadata()); public object HeaderTwo { get { return (object)GetValue(HeaderTwoProperty); } set { SetValue(HeaderTwoProperty, value);} } } And here is the Template (which by the way is created by blend from the beginning): <ControlTemplate TargetType="{x:Type Controls:TwoHeaderedGroupBox}"> <Grid SnapsToDevicePixels="true"> <Grid.ColumnDefinitions> <ColumnDefinition Width="6"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="6"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="6"/> </Grid.RowDefinitions> <Border BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Grid.Column="0" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"/> <Border x:Name="Header" Grid.Column="1" Padding="3,1,3,0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center"> <ContentControl Content="{TemplateBinding Header}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ContentPresenter Grid.ColumnSpan="2" Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="4" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"> <Border.OpacityMask> <MultiBinding ConverterParameter="7" Converter="{StaticResource BorderGapMaskConverter}"> <Binding ElementName="Header" Path="ActualWidth"/> <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/> <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/> </MultiBinding> </Border.OpacityMask> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/> </Border> </Border> <Border x:Name="HeaderTwo" Grid.Column="2" Padding="3,5,3,5" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Right"> <ContentControl Content="{TemplateBinding HeaderTwo}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" DataContext="{TemplateBinding DataContext}"/> </Border> </Grid> </ControlTemplate>

    Read the article

  • WPF Xaml Custom Styling Selected Item Style in a ListBox

    - by John Batdorf
    I have a list box that scrolls images horizontally. I have the following XAML I used blend to create it. It originally had a x:Key on the Style TaregetType line, MSDN said to remove it, as I was getting errors on that. Now I'm getting this error: Error 3 Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. I don't understand how to apply all of this junk that way, I've tried several thing, nothing is working. My goal is to have the selected item's background be white, not blue. Seems like a lot of work for something so small! Thanks. <ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Grid.Row="1" Margin="2,26,2,104" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" > <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="2,0,0,0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> <Setter Property="Background" TargetName="Bd" Value="#FFFFFFFF"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="Selector.IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Foreground" 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> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Image Source="{Binding Image}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    Read the article

  • Why does my TextBox with custom control template not have a visible text cursor?

    - by Philipp Schmid
    I have a custom control template which is set via the style property on a TextBox. The visual poperties are set correctly, even typing to the textbox works, but there is no insertion cursor (the | symbol) visible which makes editing challenging for our users. How does the control template need changing to get the traditional TextBox behavior back? <Style x:Key="DemandEditStyle" TargetType="TextBox"> <EventSetter Event="LostFocus" Handler="DemandLostFocus" /> <Setter Property="HorizontalAlignment" Value="Stretch" /> <Setter Property="VerticalAlignment" Value="Stretch" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="1" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="1" /> </Grid.RowDefinitions> <Grid.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Color="White" Offset="0" /> <GradientStop Color="White" Offset="0.15" /> <GradientStop Color="#EEE" Offset="1" /> </LinearGradientBrush> </Grid.Background> <Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="Black" /> <Border Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Background="Black" /> <Grid Grid.Row="0" Grid.Column="0" Margin="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="1" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="1" /> <RowDefinition Height="*" /> <RowDefinition Height="1" /> </Grid.RowDefinitions> <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="Black" /> <Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Background="Black" /> <Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Background="#CCC" /> <Border Grid.Row="0" Grid.Column="2" Grid.RowSpan="3" Background="#CCC" /> <TextBlock Grid.Row="1" Grid.Column="1" TextAlignment="Right" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="3 0 3 0" Background="Yellow" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text}" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> Update: Replacing the inner-most TextBox with a ScrollViewer and naming it PART_ContentHost indeed shows the text insertion cursor. Trying to right-align the text in the TextBox by either setting the HorizontalContentAlignment in the Style or as a property on the ScrollViewer were unsuccessful. Suggestions?

    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

  • WPF - DataGrid Column's ToolTip visibility based on the column's data length

    - by S.C.Vidhya
    In my application, i have tried to implement the visibility of tooltip based on the dataGrid Column's text length by using a converter. I am facing some problems in displaying the toolTip text. In the ToolTip, TextBlock's text binding is not working. If its binded with some hard coded strings, it works fine. Here below is the code that i have added for the grid column... <Custom:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Text}"> <TextBlock.ToolTip> <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}" Visibility="{Binding Converter={StaticResource ToolTipVis}}"> <TextBlock Text="{Binding Text}"> </ToolTip> </TextBlock.ToolTip> </TextBlock> </DataTemplate> </Custom:DataGridTemplateColumn.CellTemplate>

    Read the article

  • WPF: how to find an element in a datatemplate from an itemscontrol

    - by EV
    Hi, I have the following problem: the application is using the custom itemscontrol called ToolBox. The elements of a toolbox are called toolboxitems and are custom contentcontrol. Now, the toolbox stores a number of images that are retrieved from a database and displayed. For that I use a datatemplate inside the toolbox control. However, when I try to drag and drop the elements, I don't get the image object but the database component. I thought that I should then traverse the structure to find the Image element. here's the code: Toolbox: public class Toolbox : ItemsControl { private Size defaultItemSize = new Size(65, 65); public Size DefaultItemSize { get { return this.defaultItemSize; } set { this.defaultItemSize = value; } } protected override DependencyObject GetContainerForItemOverride() { return new ToolboxItem(); } protected override bool IsItemItsOwnContainerOverride(object item) { return (item is ToolboxItem); } } ToolBoxItem: public class ToolboxItem : ContentControl { private Point? dragStartPoint = null; static ToolboxItem() { FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolboxItem), new FrameworkPropertyMetadata(typeof(ToolboxItem))); } protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { base.OnPreviewMouseDown(e); this.dragStartPoint = new Point?(e.GetPosition(this)); } public String url { get; private set; } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { Point position = e.GetPosition(this); if ((SystemParameters.MinimumHorizontalDragDistance <= Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) || (SystemParameters.MinimumVerticalDragDistance <= Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y)))) { string xamlString = XamlWriter.Save(this.Content); MessageBoxResult result = MessageBox.Show(xamlString); DataObject dataObject = new DataObject("DESIGNER_ITEM", xamlString); if (dataObject != null) { DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); } } e.Handled = true; } } private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild<childItem>(child); if (childOfChild != null) return childOfChild; } } return null; } } here is the xaml file for ToolBox and toolbox item: <Style TargetType="{x:Type s:ToolboxItem}"> <Setter Property="Control.Padding" Value="5" /> <Setter Property="ContentControl.HorizontalContentAlignment" Value="Stretch" /> <Setter Property="ContentControl.VerticalContentAlignment" Value="Stretch" /> <Setter Property="ToolTip" Value="{Binding ToolTip}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type s:ToolboxItem}"> <Grid> <Rectangle Name="Border" StrokeThickness="1" StrokeDashArray="2" Fill="Transparent" SnapsToDevicePixels="true" /> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" ContentTemplate="{TemplateBinding ContentTemplate}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="Border" Property="Stroke" Value="Gray" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type s:Toolbox}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="Focusable" Value="False" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True"> <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </ScrollViewer> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Margin="0,5,0,5" ItemHeight="{Binding Path=DefaultItemSize.Height, RelativeSource={RelativeSource AncestorType=s:Toolbox}}" ItemWidth="{Binding Path=DefaultItemSize.Width, RelativeSource={RelativeSource AncestorType=s:Toolbox}}" /> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> Example usage: <Toolbox x:Name="NewLibrary" DefaultItemSize="55,55" ItemsSource="{Binding}" > <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Image Source="{Binding Path=url}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </Toolbox> The object that I get is a database object. When using a static resource I get the Image object. How to retrieve this Image object from a datatemplate? I though that I could use this tutorial: http://msdn.microsoft.com/en-us/library/bb613579.aspx But it does not seem to solve the problem. Could anyone suggest a solution? Thanks!

    Read the article

  • WPF ComboBox Binding breaks when using ControlTemplate

    - by Mitch
    I have a WPF ComboBox that has been working fine until I recently created a ControlTemplate for it to enable me to change the color of the DropDown arrow. The ComboBox still works correctly except the Bound Text value now just shows the name of the Business Object rather than the bound value. I guess that binding like Text="{Binding Path=CaseDateRange}" no longer works when using a ControlTemplate, yet the ItemsSource binding on the dropdown seems to still work fine. Can anyone offer some help with how I need to change my binding when using a ControlTemplate. The code for the ControlTemplate and ComboBox is as follows <ControlTemplate x:Key="ComboBoxControlTemplate1" TargetType="{x:Type ComboBox}"> <Grid x:Name="MainGrid" SnapsToDevicePixels="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> </Grid.ColumnDefinitions> <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" OpacityMask="#FF2A3D64"> <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}"> <Border x:Name="DropDownBorder" BorderBrush="White" BorderThickness="1" CornerRadius="3" Background="{DynamicResource DialogDarkBlue}"> <ScrollViewer x:Name="DropDownScrollViewer" > <Grid RenderOptions.ClearTypeHint="Enabled"> <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/> </Canvas> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Grid> </ScrollViewer> </Border> </Microsoft_Windows_Themes:SystemDropShadowChrome> </Popup> <ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Foreground="White"> <ToggleButton.Style> <Style TargetType="{x:Type ToggleButton}"> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="IsTabStop" Value="False"/> <Setter Property="Focusable" Value="False"/> <Setter Property="ClickMode" Value="Press"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="True"> <Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> <Path x:Name="Arrow" Data="M0,0L3.5,4 7,0z" Fill="White" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/> </Grid> </Microsoft_Windows_Themes:ButtonChrome> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Fill" TargetName="Arrow" Value="#FFAFAFAF"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ToggleButton.Style> </ToggleButton> <ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True"> <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/> <Setter Property="Color" TargetName="Shdw" Value="#71000000"/> </Trigger> <Trigger Property="HasItems" Value="False"> <Setter Property="Height" TargetName="DropDownBorder" Value="95"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> <Setter Property="Background" Value="#FFF4F4F4"/> </Trigger> <Trigger Property="IsGrouping" Value="True"> <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> </Trigger> <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False"> <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/> <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> And the ComboBox is <ComboBox x:Name="cboSelectedCase" Text="{Binding Path=CaseDateRange}" DisplayMemberPath="CaseDateRange" SelectedValuePath="CaseID" Template="{DynamicResource ComboBoxControlTemplate1}" />

    Read the article

  • XAML trigger as StaticResource

    - by adrianm
    Why can't I create a trigger and use it as a static resource in XAML? <Window.Resources> <Trigger x:Key="ValidationTrigger" x:Shared="False" Property="Validation.HasError" Value="true"> <Setter Property="FrameworkElement.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)/ErrorContent}"/> </Trigger> <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> <Style.Triggers> <StaticResource ResourceKey="ValidationTrigger"/> </Style.Triggers> </Style> </Window.Resources> I get an errormessage at runtime "Value cannot be null. Parameter name: triggerBase Error at object 'System.Windows.Markup.StaticResourceHolder' in markup file"

    Read the article

  • WPF Lookless Control Events

    - by Scott
    I have the following class: public class LooklessControl : Control { public List<int> IntList { get; private set; } public int CurrentInt { get; private set; } private int _index = 0; static LooklessControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(LooklessControl), new FrameworkPropertyMetadata(typeof(LooklessControl))); } public LooklessControl() { IntList = new List<int>(); for (int i = 0; i < 10; i++) { IntList.Add(i); } CurrentInt = IntList[_index]; } public static readonly RoutedCommand NextItemCommand = new RoutedCommand("NextItemCommand", typeof(LooklessControl)); private void ExecutedNextItemCommand(object sender, ExecutedRoutedEventArgs e) { NextItemHandler(); } private void CanExecuteNextItemCommand(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } public static readonly RoutedCommand PrevItemCommand = new RoutedCommand("PrevItemCommand", typeof(LooklessControl)); private void ExecutedPrevItemCommand(ExecutedRoutedEventArgs e) { PrevItemHandler(); } private void CanExecutePrevItemCommand(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } public static readonly RoutedEvent NextItemEvent = EventManager.RegisterRoutedEvent("NextItemEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(LooklessControl)); public event RoutedEventHandler NextItem { add { AddHandler(NextItemEvent, value); } remove { RemoveHandler(NextItemEvent, value); } } private void RaiseNextItemEvent() { RoutedEventArgs args = new RoutedEventArgs(LooklessControl.NextItemEvent); RaiseEvent(args); } public static readonly RoutedEvent PrevItemEvent = EventManager.RegisterRoutedEvent("PrevItemEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(LooklessControl)); public event RoutedEventHandler PrevItem { add { AddHandler(PrevItemEvent, value); } remove { RemoveHandler(PrevItemEvent, value); } } private void RaisePrevItemEvent() { RoutedEventArgs args = new RoutedEventArgs(LooklessControl.PrevItemEvent); RaiseEvent(args); } private void NextItemHandler() { _index++; if (_index == IntList.Count) { _index = 0; } CurrentInt = IntList[_index]; RaiseNextItemEvent(); } private void PrevItemHandler() { _index--; if (_index == 0) { _index = IntList.Count - 1; } CurrentInt = IntList[_index]; RaisePrevItemEvent(); } } The class has a default style, in Generic.xaml, that looks like this: <Style x:Key="{x:Type local:LooklessControl}" TargetType="{x:Type local:LooklessControl}"> <Setter Property="Height" Value="200"/> <Setter Property="Width" Value="90"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:LooklessControl}"> <Border BorderBrush="Black" BorderThickness="1" Padding="2"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="20"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Rectangle Grid.Row="0" Fill="LightGray"/> <Rectangle Grid.Row="1" Fill="Gainsboro"/> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="10"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="10"/> </Grid.ColumnDefinitions> <Path Grid.Column="0" x:Name="pathLeftArrow" Data="M0,0.5 L1,1 1,0Z" Width="6" Height="14" Stretch="Fill" HorizontalAlignment="Center" Fill="SlateBlue"/> <TextBlock Grid.Column="1" Name="textBlock" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CurrentInt}" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Junction" FontSize="13"/> <Path Grid.Column="2" x:Name="pathRightArrow" Data="M0,0 L1,0.5 0,1Z" Width="6" Height="14" Stretch="Fill" HorizontalAlignment="Center" Fill="SlateBlue"/> </Grid> <ListBox Grid.Row="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Background="Transparent" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IntList}"/> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> How do I make it so that when the user clicks on pathLeftArrow it fires LooklessControl.PrevItemCommand, or or they click on pathRightArrow and it fires LooklessControl.NextItemCommand, or they click on an item in the ListBox and LooklessControl is notified of the newly selected item? In other words, without adding x:Class to the top of Generic.xaml and thus creating a code-behind file for it, which I assume you wouldn't want to do, how do you handle events for elements in your xaml that don't have a Command property (which is just about everything other than a Button)? Should LooklessControl have it's own XAML file (much like what you get when you create a new UserControl) associated with it that Generic.xaml just pulls in as a MergedDictionar as its default template? Or is there some other acknowledged way to do what I'm trying to do?

    Read the article

  • [WPF] SelectionChanged of a child ListBox

    - by quimbs
    Hi, I have a ListBox bound to an ObservableCollection with an ItemTemplate that contains another ListBox. First of all, I tried to get the last selected item of all the listboxes (either the parent and the inner ones) from my MainWindowViewModel this way: public object SelectedItem { get { return this.selectedItem; } set { this.selectedItem = value; base.NotifyPropertyChanged("SelectedItem"); } } So, for example, in the DataTemplate of the items of the parent ListBox I've got this: <ListBox ItemsSource="{Binding Tails}" SelectedItem="{Binding Path=DataContext.SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/> The problem now, is that when I select an item from the parent ListBox and then an item from a child listbox, I get this: http://i40.tinypic.com/j7bvig.jpg As you can see, two items are selected at the same time. How can I solve that? Thanks in advance.

    Read the article

  • How to delay the Setter to be in affect for 0.5 sec in DataTrigger ?

    - by vladc77
    I am wondering if it possible to delay a datatrigger to change layout for 0.5 a second. Is any easy way to do it? I need to set the visibility of the object but wait for 0.5 a second. Any adeas are highly appreciated. <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}}, Path=SelectedItem.Attributes[retract].Value}" Value="True"> <Setter TargetName="ListboxIemtextBlock" Property="Visibility" Value="Hidden" /> </DataTrigger>

    Read the article

  • Binding list of objects to WPF ListView

    - by Dave Colwell
    Hi all, I have a list of objects which i want to bind to a ListView control in my WPF application. The Objects have a DataTemplate already, so no need to define that. The list of objects is a property in the codebehind file in the format list<object> When i add one object programatically, it appears fine. But when i try to bind the ItemSource of the ListBox to the list of objects, nothing shows up. I am using the following binding: ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Portfolios}" where the name of the property i am trying to bind to is Portfolios and exists on the parent window

    Read the article

  • Problem with binding from style

    - by Maurizio Reginelli
    I have this block of xaml and I made a ViewModel which contains a property called MyBrush. I would like to set the grid background to that property but this block doesn't work. Could you tell me how can I do that? <Style x:Key="myKey" TargetType="myType"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="myType"> <Grid Background="{Binding RelativeSource={RelativeSource Self}, Path=MyBrush}"> ...

    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

  • Dependency property does not work within a geometry in a controltemplate

    - by Erik Bongers
    I have a DepencencyProperty (a boolean) that works fine on an Ellipse, but not on an ArcSegment. Am I doing something that is not possible? Here's part of the xaml. Both the TemplateBindings of Origin and LargeArc do not work in the geometry. But the LargeArc DependencyProperty does work in the Ellipse, so my DependencyProperty seems to be set up correctly. <ControlTemplate TargetType="{x:Type nodes:TestCircle}"> <Canvas Background="AliceBlue"> <Ellipse Height="10" Width="10" Fill="Yellow" Visibility="{TemplateBinding LargeArc, Converter={StaticResource BoolToVisConverter}}"/> <Path Canvas.Left="0" Canvas.Top="0" Stroke="Black" StrokeThickness="3"> <Path.Data> <GeometryGroup> <PathGeometry> <PathFigure IsClosed="True" StartPoint="{TemplateBinding Origin}"> <LineSegment Point="150,100" /> <ArcSegment Point="140,150" IsLargeArc="{TemplateBinding LargeArc}" Size="50,50" SweepDirection="Clockwise"/> </PathFigure> </PathGeometry> </GeometryGroup> </Path.Data> </Path> </Canvas> </ControlTemplate> What I'm trying to build is a (sort of) pie-shaped usercontrol where the shape of the Pie is defined by DependencyProperties and the actual graphics used are in a template, so they can be replaced or customized. In other words: I would like the code-behind to be visual-free (which, I assume, is good separation). SOLUTION--------------------------(I'm not allowed to answer my own questions yet) I found the answer myself, and this can be useful for others encountering the same issue. This is why the TemplateBinding on the Geometry failed: A TemplateBinding will only work when binding a DependencyProperty to another DependencyProperty. Following article set me on the right track: http://blogs.msdn.com/b/liviuc/archive/2009/12/14/wpf-templatebinding-vs-relativesource-templatedparent.aspx The ArcSegment properties are no DependencyProperties. Thus, the solution to the above problem is to replace <ArcSegment Point="140,150" IsLargeArc="{TemplateBinding LargeArc}" with <ArcSegment Point="140,150" IsLargeArc="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=LargeArc}" Colin, your working example where an 'ordinary' binding was used in the geometry set me on the right track. BTW, love the infographics and the construction of your UserControl in your blogpost. And, hey, that quick tip on code snippets, and especially on that DP attribute and the separation of those DPs into a partial class file is pure gold!

    Read the article

  • Why does the data binding in this validation example work?

    - by MartyIX
    I'm wondering how exactly the XAML sample (MSDN sample) works: <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> </Style> Questions: (Validation.Errors)[0].ErrorContent - Is this code somehow checked by WPF? Because Validation.Errors may be an empty collection and in ordinary C# code this code may throw an exception. If this data-binding returns null for valid input - the null value is then casted to empty string (in a text control for example)? The index 0 corresponds to the first error message. How can I return more error messages from Validate method? Thank you for responses!

    Read the article

  • DataContext as Source for Converter Binding Within Resources

    - by loafofbread
    <Style TargetType="{x:Type local:SomeControl}"> <Canvas.DataContext> <ViewModels:VMSomeControl Model="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> </Canvas.DataContext> <Canvas.Resources> <!-- is there a way to use a binding that points to the datacontext within the resources ? --> <Converters:SomeConverter x:Key="someConverter" SomeProperty="{Binding Path=Model.SomeProperty}" /> <!-- is there a way to point Directly to the TemplatedParent ? --> <Converters:SomeConverter x:Key="someConverter" SomeProperty="{TemplateBinding Path=SomeProperty}" /> </Canvas.Resources> <SomeFrameworkElement SomeProperty="{Binding Path=Model.SomeOtherProperty, Converter={StaticResource someConverter}}" /> </Canvas> is it possible to use bindings that use either the dataContext or the TemplatedParent Within a ControlTemplate's Root Visuals resourecs ?

    Read the article

  • Silverlight 3 DataBinding with ValueConverter: conditionally use the default value for property

    - by eriksmith200
    I have a DatePicker for which I want to set the BorderBrush to SolidColorBrush(Colors.Red) if the SelectedDate is null. If a date has been filled in though, I want to just have the default BorderBrush. I still want to be able to style the default BorderBrush in Blend, so I don't want to hardcode the default borderbrush of the DatePicker. So basically: xaml: <controls:DatePicker BorderBrush="{Binding SelectedDate, RelativeSource={RelativeSource Self}, Converter={StaticResource BrushConverter}, Mode=OneWay}"/> c#: public class BrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value == null ? new SolidColorBrush(Colors.Red) : /* when value != null have the bound property use it's default value */ } is this possible?

    Read the article

  • Is there a cleaner way to Bind property to owner's DataContext?

    - by Dan Bryant
    I have some code that looks like this: <Expander Header="{Binding SelectedSlot.Name}" Visibility="{Binding ShowGroupSlot, Converter={StaticResource BooleanToVisibility}}"> <Controls:GroupPrototypeSlotControl Slot="{Binding DataContext.SelectedSlot, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}}" /> </Expander> This works, but the ugliness of the Slot Binding bothers me. This is required because the GroupPrototypeSlotControl has a GroupPrototypeViewModel as its DataContext. If I simply use {Binding SelectedSlot}, it attempts to resolve it on the 'child' ViewModel, which fails. I get around this by explicitly looking at the DataContext of my parent control. Is there a cleaner way to do this type of binding?

    Read the article

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