I have a TabItem that has it's DataContext set to a ViewModel.
The header is set to a header View and the Content is set to an item view
However this Binding from the item view just doesn't work
<TextBox Margin="0" Grid.Column="0" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.SourceCode, Mode=TwoWay}"/>
yet this binding
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.Name}"/>
which is in the header view works fine.
I've even tried putting the TextBlock from the Header into the Item and setting the Content to a new HeaderView. No matter what I try I can't get the bindings from the Content to work even though the header binding works fine
Can anyone explain?
Adding the full Views as requested first the Item
<UserControl x:Class="IE.Intergration.JobBuilder.Views.TabbedJobs.TabbedJobItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=New.TabbedJobs.TabbedJobItem}"
>
<UserControl.Resources>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" >
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<TextBox Margin="0" Grid.Column="0" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.SourceCode, Mode=TwoWay}"/>
<StackPanel Grid.Column="0" Grid.Row="1" FlowDirection="LeftToRight" Orientation="Horizontal">
<Button Content="Save" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Save}" />
</StackPanel>
</Grid>
and the Header
<UserControl x:Class="IE.Intergration.JobBuilder.Views.TabbedJobs.TabbedJobItemHeader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=New.TabbedJobs.TabJobHeader}"
>
<Grid x:Name="LayoutRoot">
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=sdk:TabItem, AncestorLevel=1}, Path=DataContext.Job.Name}"/>
</Grid>
Related
Current custom window(base) is:
<Window x:Class="Views.DialogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Views"
xmlns:dialog="clr-namespace:ViewModels"
mc:Ignorable="d"
Title="DialogWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" Background="Transparent" ResizeMode="CanResizeWithGrip" SizeToContent="WidthAndHeight">
<Window.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type dialog:Dialog_1ViewModel}">
<local:Dialog_1></local:Dialog_1>
</DataTemplate>
</ResourceDictionary>
</Window.Resources>
<ContentPresenter x:Name="ContentPresenter" Content="{Binding}"></ContentPresenter>
</Window>
Window in designer:
Its DataContext is set to an instance of UserControl:
<UserControl x:Class="Views.Dialog_1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Views"
xmlns:t1="clr-namespace:Windows"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600">
<UserControl.Resources>
<ResourceDictionary>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"></Setter>
</Style>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Resource_1.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border CornerRadius="4" Background="#ffff" BorderThickness="1" BorderBrush="#9888">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="12*"/>
<RowDefinition Height="15*"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="#f999" Cursor="Hand" MouseDown="Border_MouseDown">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Header"></TextBlock>
</Border>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" MinWidth="150"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="4">
<Image Source="C:\test.png"></Image>
</Grid>
<Grid Grid.Column="1" Margin="4">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<DockPanel>
<TextBlock Text="Foo: " FontWeight="Bold" Margin="0,0,4,0"></TextBlock>
<TextBlock Text="Bar"></TextBlock>
</DockPanel>
<DockPanel Margin="0,8,0,0">
<TextBlock Text="Foo: " FontWeight="Bold" Margin="0,0,4,0"></TextBlock>
<TextBlock Text="Bar"></TextBlock>
</DockPanel>
<DockPanel>
<TextBlock Text="Foo: " FontWeight="Bold" Margin="0,0,4,0"></TextBlock>
<TextBlock Text="Bar"></TextBlock>
</DockPanel>
<DockPanel>
<TextBlock Text="Foo: " FontWeight="Bold" Margin="0,0,4,0"></TextBlock>
<TextBlock Text="Bar"></TextBlock>
</DockPanel>
</StackPanel>
<DockPanel Grid.Row="1" VerticalAlignment="Center">
<TextBlock Text="Foo: " FontWeight="Bold" Margin="0,0,4,0"/>
<TextBlock Text="Bar"/>
</DockPanel>
</Grid>
</Grid>
<DataGrid Grid.Row="2" Background="#ff88" ColumnWidth="Auto" VerticalAlignment="Stretch" AutoGenerateColumns="False" ItemsSource="{Binding data_1}">
<DataGridTextColumn Header="Name" MinWidth="200" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Description" MinWidth="100" Binding="{Binding Description}"/>
</DataGrid>
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="#f999">
<Grid HorizontalAlignment="Right" Margin="4">
<Button Style="{StaticResource T_button_1}" HorizontalAlignment="Right" VerticalAlignment="Center" Width="100" Command="{Binding C_No}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}" t1:Button_1.Icon="/Icons/no.png" t1:Button_1.Label="Cancel"/>
<Button Style="{StaticResource T_button_1}" HorizontalAlignment="Right" VerticalAlignment="Center" Width="100" Command="{Binding C_Yes}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}" Margin="0,0,105,0"/>
</Grid>
</Border>
</Grid>
</Border>
</UserControl>
UserControl in designer:
The result(run and resize process):
Close look shows interesting behaviour(seems like style changes):
Edit 1
Made some more minimized version:
<UserControl x:Class="Views.Dialog_1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600">
<UserControl.Resources>
<ResourceDictionary>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"></Setter>
</Style>
<Style TargetType="Grid">
<Setter Property="ShowGridLines" Value="True"></Setter>
</Style>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Resource_1.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border Background="#ffff" BorderThickness="1" BorderBrush="#ccc">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="2*"/>
<RowDefinition Height="3*"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0">
</Border>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="4">
<Image Source="C:\test.ico"></Image>
</Grid>
<Grid Grid.Column="1" Margin="4">
</Grid>
</Grid>
<Grid Grid.Row="2">
</Grid>
<Border Grid.Row="3">
</Border>
</Grid>
</Border>
</UserControl>
When run:
What could cause such issue where controls' initial sizes are oddly wrong and after resizing they return to "normal" or how would it be possible to fix/escape that situation leaving similar logic with custom UserControl of Window?
May this be caused by ContentPresenter part?
I'm using MVVM pattern in WPF. My small project contains 1x Window and 3x UserControls. Each UserControl represents tab, please see the picture below.
Solution structure
What I'm trying to do is to bind the Window Title to the variable in each tab model. I tried to use Interaction.Triggers and event name "Loaded". The command "ChangeTitle" works fine when I switch between different views but when I select tab with the same view as previously selected tab then title doesn't change until I switch to another tab with different view. I tried other events but couldn't find any for this purpose. I would like to trigger the above command after tab selection changed. Please advise. Thank you.
MainWindow.xaml
<Window x:Class="LSS_doc.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:intr="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:models="clr-namespace:LSS_doc.Models"
xmlns:Views="clr-namespace:LSS_doc.Views"
mc:Ignorable="d"
Height="350" Width="525"
MinHeight="350"
MinWidth="525">
<Grid>
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="Loaded">
<intr:InvokeCommandAction Command="{Binding CreateMainTab}"/>
</intr:EventTrigger>
</intr:Interaction.Triggers>
<DockPanel>
<TabControl Name="tabControl" ItemsSource="{Binding Tabs}" SelectedIndex="{Binding TabIndex}">
<TabControl.Resources>
<DataTemplate DataType="{x:Type models:MainTabModel}">
<Views:MainTabView/>
</DataTemplate>
<DataTemplate DataType="{x:Type models:ResultTabModel}">
<Views:ResultTabView/>
</DataTemplate>
<DataTemplate DataType="{x:Type models:DisplayTabView}">
<Views:DisplayTabView/>
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:ITabModel}">
<TextBlock>
<Run Text="{Binding Name}"/>
<Hyperlink Command="{Binding CloseCommand}" ><Run Text="{Binding CloseButton}"/></Hyperlink>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</DockPanel>
</Grid>
MainTabView.xaml
<UserControl x:Class="LSS_doc.Views.MainTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:intr="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="Loaded">
<intr:InvokeCommandAction CommandParameter="{Binding Name}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChangeTitle}"/>
</intr:EventTrigger>
</intr:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Name="searchBox" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Keywords}" Margin="10,10,10,10" Height="30"/>
<Button Name="searchButton" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Search}" Grid.Column="1" Margin="0,0,10,0" Height="30"/>
<TreeView Grid.Row="1" Grid.ColumnSpan="2" Margin="10,0,10,10" BorderThickness="0">
<TreeViewItem Header="{Binding Name}" IsExpanded="True">
<TreeViewItem Header="Level 2.1" />
<TreeViewItem Header="Level 2.2" IsExpanded="True">
<TreeViewItem Header="Level 3.1" />
<TreeViewItem Header="Level 3.2" />
</TreeViewItem>
<TreeViewItem Header="Level 2.3" />
</TreeViewItem>
</TreeView>
</Grid>
ResultTabView.xaml
<UserControl x:Class="LSS_doc.Views.ResultTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:intr="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="Loaded">
<intr:InvokeCommandAction CommandParameter="{Binding Name}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChangeTitle}"/>
</intr:EventTrigger>
</intr:Interaction.Triggers>
<Grid>
<ListBox x:Name="FileList" ItemsSource="{Binding Result}">
<ListBox.ItemTemplate>
<DataTemplate DataType="string">
<TextBlock>
<Hyperlink CommandParameter="{Binding}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.DisplayFile}">
<TextBlock Text="{Binding}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
DisplayTabView.xaml
<UserControl x:Class="LSS_doc.Views.DisplayTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:intr="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LSS_doc.Helpers"
xmlns:ns="clr-namespace:LSS_doc.Helpers"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="Loaded">
<intr:InvokeCommandAction CommandParameter="{Binding Name}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChangeTitle}"/>
</intr:EventTrigger>
</intr:Interaction.Triggers>
<Grid >
<WebBrowser local:WebBrowserExtensions.BindableSource="{Binding FileUrl}" local:WebBrowserExtensions.BindableLoaded="{Binding AcceptedKeywords}"/>
</Grid>
You can bind Window Title directly to model using ElementName:
<Window Title="{Binding ElementName=tab,Path=SelectedItem.WindowTitleForThisTab}">
I am having trouble getting a ScrollViewer to work properly if it's not the only element in the window. I want to scroll through a list of items(a list set as ItemsSource) but also want other elements to be visible in my window. Now i don't know how to set the height relative to the other elements. Is that even a valid approach or am i doing it completly wrong?
<Window x:Class="FactorioWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FactorioWpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
Closing="Window_Closing">
<StackPanel>
<Menu>
<MenuItem Header="Items">
<MenuItem Header="Add" Click="ItemsAdd_Click" />
</MenuItem>
</Menu>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0">
<ItemsControl Name="ItemViewerItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</StackPanel>
I searched for nearly three hours but the only solutions i could find, were to set the scroll viewer as the top element.
It is not gonna work with StackPanel. StackPanel grows based on content. Actually it will work with stack panel but you need to define height of ScrollViewer. Use grid with row definitions.
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication3"
mc:Ignorable="d" Height="350" Width="525" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu Grid.Row="0">
<MenuItem Header="Items">
<MenuItem Header="Add" Click="MenuItem_OnClick" />
</MenuItem>
</Menu>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Column="0">
<ItemsControl Name="ItemViewerItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Grid>
</Window>
I have a reusable custom control for search results. It uses ListView GridView to display the search results and it's already used in multiple places in my app.
<views:AbstractDictionaryPickerView x:Class="MyApp.Common.Controls.Dictionaries.Views.AbstractDictionaryPickerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:watermark="clr-namespace:MyApp.Common.Controls.Watermark"
xmlns:behaviors="clr-namespace:MyApp.Common.Behaviors"
xmlns:listViewLayout="clr-namespace:Itenso.Windows.Controls.ListViewLayout;assembly=Itenso.Windows.Controls.ListViewLayout"
xmlns:views="clr-namespace:MyApp.Common.Controls.Dictionaries.Views"
xmlns:viewModels="clr-namespace:MyApp.Common.Controls.Dictionaries.ViewModels"
xmlns:design="clr-namespace:MyApp.Common.Controls.Dictionaries.ViewModels.Design"
d:DataContext="{design:DesignMultiDictionaryPickerViewModel}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Viewbox Stretch="Fill">
<Canvas Width="800" Height="800">
<Rectangle Fill="#ffffffff" Width="800" Height="800" />
<Rectangle Width="5" Height="800" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFCAEBF4"/>
<GradientStop Color="#FFCEF5FF" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Viewbox>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBox
Grid.Row="0" Height="Auto"
Margin="5,0,5,0"
Style="{StaticResource TextBoxStyle}"
Text="{Binding SearchQuery, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Behaviors>
<watermark:TextBoxWatermarkBehavior Label="{Binding WatermarkText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
LabelStyle="{StaticResource WatermarkStyle}"/>
<behaviors:SelectAllWhenTextBoxFocusedBehavior/>
<behaviors:TextBoxArrowUpDownNavigationBehavior/>
<behaviors:SetLogicalFocusBehavior/>
</i:Interaction.Behaviors>
</TextBox>
<Grid Grid.Row="1">
<ListView listViewLayout:ListViewLayoutManager.Enabled="True" x:Name="SearchResultsList"
ItemsSource="{Binding FilteredElements}"
ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="5,2,5,3"
SelectionMode="Single"
>
<ListView.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyle}"/>
</ListView.Resources>
<i:Interaction.Behaviors>
<behaviors:ArrowNavigationBehavior/>
<behaviors:AutoSizeListViewColumns/>
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDoubleClick">
<i:InvokeCommandAction Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}" />
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}" />
</ListView.InputBindings>
<ListView.View>
<!-- GRIDVIEW TO REPLACE -->
<GridView ColumnHeaderContainerStyle="{StaticResource {x:Type GridViewColumnHeader}}" x:Name="ElementsGridView">
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="viewModels:ChoosableViewModel">
<CheckBox IsChecked="{Binding IsChosen}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
</Grid>
</views:AbstractDictionaryPickerView>
The consuming code looks like that:
<UserControl x:Class="MyApp.Modules.Management.OnlineRegistrationSettings.Tabs.AvailableDoctors.OnlineRegistrationDoctorsSettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:views="clr-namespace:MyApp.Common.Controls.Dictionaries.Views;assembly=MyApp.Common"
xmlns:onlineRegistrationSettings="clr-namespace:MyApp.Modules.Management.OnlineRegistrationSettings"
d:DataContext="{d:DesignInstance onlineRegistrationSettings:OnlineRegistrationSettingsViewModel}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Style="{StaticResource LabelStyle}" Content="Wybór lekarzy, którzy mają być dostępni w rejestracji online."/>
<!-- HERE -->
<views:AbstractDictionaryPickerView DataContext="{Binding MultiDictionaryPickerViewModel}" Grid.Row="1"
Configuration="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.Configuration}"/>
</Grid>
</UserControl>
Now I want do modify the GridView columns (add a new column with ComboBox).
Is it possible to override the GridView element of the views:AbstractDictionaryPickerView in the XAML of the consuming code? I mean what's below <!-- GRIDVIEW TO REPLACE --> tag in the first snippet.
Is it possible to override the GridView element of the views:AbstractDictionaryPickerView in the XAML of the consuming code?
No. At least not using only XAML.
But if you add a property to your AbstractDictionaryPickerView control that exposes the view of the ListView:
public partial class AbstractDictionaryPickerView : UserControl
{
public AbstractDictionaryPickerView()
{
InitializeComponent();
}
public ViewBase GridView
{
get { return SearchResultsList.View; }
set { SearchResultsList.View = value; }
}
}
...you could set the it to a new GridView in the consuming XAML markup:
<views:AbstractDictionaryPickerView>
<views:AbstractDictionaryPickerView.GridView>
<GridView>
<GridView.Columns>
<GridViewColumn Header="..." DisplayMemberBinding="{Binding}" />
</GridView.Columns>
</GridView>
</views:AbstractDictionaryPickerView.GridView>
</views:AbstractDictionaryPickerView>
I'm building an app in which I have created a UserControlthat has a second UserControl inside of it.
Here is the first UserControl:
<UserControl x:Class="TasksMonitor.CustomControls.TaskCardBtn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TasksMonitor.CustomControls"
mc:Ignorable="d"
Name="TaskCardBtnCustomControl"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../CustomButtonsStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ToolTip"></Style>
</ResourceDictionary>
</UserControl.Resources>
<Button Click="OnButtonClick" Style="{DynamicResource FlatCntrlBtn}">
<Grid Width="{Binding ActualWidth, ElementName=TaskCardBtnCustomControl}" VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="15"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<Canvas Margin="4,10,0,0" Grid.Column="1">
<Ellipse Width="15" Height="15" Fill="{Binding Path=StatusColor, ElementName=TaskCardBtnCustomControl, FallbackValue=#FFFFFF}"/>
</Canvas>
<TextBlock VerticalAlignment="Center" x:Name="BtnTitle" Grid.Column="3" Text="{Binding Path=BtnText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
</Grid>
</Button>
</UserControl>
That UserControl is inside of this UserControl:
<UserControl x:Class="TasksMonitor.CustomControls.TaskCardUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TasksMonitor"
xmlns:ut="clr-namespace:TasksMonitor.Utils"
xmlns:cc="clr-namespace:TasksMonitor.CustomControls"
Name="TaskCardUC"
mc:Ignorable="d"
Margin="5"
d:DesignHeight="35" d:DesignWidth="300">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="Icons" Source="../Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
<ut:StatusToColorConverter x:Key="StatusToColor"/>
</ResourceDictionary>
</UserControl.Resources>
<Grid Width="auto">
<Grid Background="#2B2B2B">
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<cc:TaskCardBtn StatusColor="{Binding TskStatus, Converter={StaticResource StatusToColor}}" BtnText="{Binding Path=StuffYeah, ElementName=TaskCardUC}" x:Name="ExpandCollapseBtn" BtnClick="GridContentControl_Expand"/>
</Grid>
<Grid Grid.Row="1" Background="#2B2B2B" Name="GridContent" >
<UserControl Margin="10" Loaded="GridContentControl_Loaded">
</UserControl>
</Grid>
</Grid>
</Grid>
</UserControl>
The second UserControl or Parent UserControl is being used in a DataTemplate:
<Grid.Resources>
<DataTemplate x:Key="itemTemplate">
<cc:TaskCardUserControl StuffYeah="{Binding BtnTxt}"/>
</DataTemplate>
</Grid.Resources>
When I set the Bind to BtnTxt as illustrated in the DataTemplate above it does not work and says that it can't find 'BtnTxt' in object TaskCardUserControl. I feel that this is a binding issue as I have a property from the first UserControl bound to the parent property and then that parent property bound to the DataTemplate. I'm very new to DataTemplates and UserControl in general, would someone be able to point me in the correct direction?
Thanks in advance.
I figured this out...I was setting this.DataContext = this in the code which was actually old code. Once I commented this out everything works as it should. Thanks for the help.