Can you use 2 different ViewModels in a Grid?
One ViewModel to fill a ComboBox and another ViewModel to get the selectedItem?
Like this sample (not working):
<Grid Grid.Row="4"
DataContext="{Binding ViewModel1, Mode=OneWay, Source={StaticResource Locator}}">
<TextBlock Grid.Row="4"
Text="Language:"
FontWeight="Bold"
VerticalAlignment="Center" />
<ComboBox Grid.Column="1"
DisplayMemberPath="Value"
VerticalAlignment="Center"
Width="200"
ItemsSource="{Binding LanguageList}"
DataContext="{Binding ViewModel2, Mode=OneWay, Source={StaticResource Locator}}"
SelectedItem="{Binding SelectedLanguage}"/>
</Grid>
You could specify an explicit source for each binding:
<Grid Grid.Row="4">
<TextBlock Grid.Row="4"
Text="Language:"
FontWeight="Bold"
VerticalAlignment="Center" />
<ComboBox Grid.Column="1"
DisplayMemberPath="Value"
VerticalAlignment="Center"
Width="200"
ItemsSource="{Binding ViewModel1.LanguageList, Source={StaticResource Locator}}"
SelectedItem="{Binding ViewModel2.SelectedLanguage, Source={StaticResource Locator}}"/>
</Grid>
Related
In this xaml snippet I tried to specify the ViewModel and the Locator for the x DataType to change the bindings to x:Bind, but unfortunately that doesn't work here. Why can't I simply omit the specification of Source={StaticResource Locator} and address the whole thing via the x DataType, what am I doing wrong?
<DataTemplate x:Key="appointmentTemplate" >
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding CalendarUCView.GridTappedCommand, Source={StaticResource Locator}}"/>
</core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<ListView ItemsSource="{Binding Converter={StaticResource cellModelToEventsConverter}, Mode=TwoWay}"
VerticalAlignment="Top"
Grid.Row="0"
Style="{StaticResource appointmentCellListViewStyle}"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding CalendarUCView.SelectedAppointment, Source={StaticResource Locator}, Mode=TwoWay}">
<Interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding CalendarUCView.ItemTappedCommand, Source={StaticResource Locator}}"/>
</core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</ListView>
<TextBlock HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Grid.Row="1"
Text="{Binding Converter={StaticResource cellModelToDayConverter}, Mode=OneWay}"
Margin="4"/>
</Grid>
</DataTemplate>
I tryed:
<DataTemplate x:Key="appointmentTemplate"
x:DataType="viewModel:CalendarUCViewModel" >
and also:
<DataTemplate x:Key="appointmentTemplate"
x:DataType="locator:CalendarUCView" >
So usually I can do this:
Command="{x:Bind GridTappedCommand}"
instead of that:
Command="{Binding CalendarUCView.GridTappedCommand, Source={StaticResource Locator}}"
Or if I change the x:DataType to the View (x:DataType="local:CalendarUCView") and use in View:
public CalendarUCViewModel Vm
{
get => (CalendarUCViewModel)DataContext;
}
usually can do this:
Command="{x:Bind Vm.GridTappedCommand}"
I'm working in the mvvm pattern design.
After a while, I can use the devExpress dialogService as I want.
I have to bind, from my mainWindowViewModel, two data: a collection to populate a combobox and an object, binded to the layout control (this dialog is used to insert a new item).
In the head of my usercontrol, showed in the dialog, I have:
DataContext="{dxmvvm:ViewModelSource vm:MainWindowViewModel}"
The collection is binded correctly, in this way:
While the not working binding is:
<dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" Margin="0,10,0,0"
DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},
Path=DataContext.impiantoVuoto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
The layoutControl is simply binded to an empty object. When I write the new fields and click "ok", it has to save these data, thanks to the binding. But this doesn't work, when I go the mainViewModel, the empty object is still empty. Why?
This is my whole usercontrol:
<UserControl x:Class="MyNS.View.Generic.nuovoImpianto"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNS"
xmlns:vm="clr-namespace:MyNS.ViewModel"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:View="clr-namespace:MyNS.View"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
DataContext="{dxmvvm:ViewModelSource vm:MainWindowViewModel}"
>
<UserControl.Resources>
<vm:InverseBooleanConverter x:Key="InverseBooleanConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" Margin="0,10,0,0"
DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},
Path=DataContext.impiantoVuoto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<dxlc:LayoutGroup Header="Info generali" View="GroupBox" Orientation="Vertical" >
<dxlc:LayoutItem Label="Codice">
<dxe:TextEdit EditValue="{Binding CODICE}" />
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Nome">
<dxe:TextEdit EditValue="{Binding NOME}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Città">
<dxe:TextEdit EditValue="{Binding LOCALITA}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Indirizzo">
<dxe:TextEdit EditValue="{Binding INDIRIZZO}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="CAP">
<dxe:TextEdit EditValue="{Binding CAP}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="P. IVA">
<dxe:TextEdit EditValue="{Binding PIVA}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Telefono">
<dxe:TextEdit EditValue="{Binding TELEFONO}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Responsabile">
<dxe:TextEdit EditValue="{Binding RESPONSABILE}"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="E-mail">
<dxe:TextEdit EditValue="{Binding EMAILS}"/>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
<dxlc:LayoutGroup Header="Configurazione tecnica" View="GroupBox" Orientation="Vertical">
<dxlc:LayoutItem Label="Tipo sistema">
<dxe:ComboBoxEdit IsTextEditable="False" EditValue="{Binding IDTTS}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},Path=DataContext.tts}" />
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Locazione">
<StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
<RadioButton Content="{DynamicResource Locale}" Margin="10,0,0,0" x:Name="rd_LOCALE" VerticalAlignment="Center"
GroupName="LocationL" Panel.ZIndex="9" TabIndex="10" />
<RadioButton Content="{DynamicResource Remoto}" Margin="10,0,6,0" x:Name="rd_REMOTO" VerticalAlignment="Center"
IsChecked="{Binding REMOTO}" GroupName="LocationR" Panel.ZIndex="10" TabIndex="11" Tag="PRISMA"/>
</StackPanel>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Tipo di connessione">
<StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton x:Name="rd_TIPOCONN" Content="{DynamicResource Terminale}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnT"
Panel.ZIndex="11" TabIndex="12" />
<RadioButton x:Name="rd_SLAVE" Content="Slave" Margin="10,0,6,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnS"
IsChecked="{Binding TIPOCONN}" Panel.ZIndex="12" TabIndex="13" />
</StackPanel>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
<dxlc:LayoutGroup Header="Centralina STK" View="GroupBox" Orientation="Vertical">
<dxlc:LayoutItem >
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,6">
<RadioButton x:Name="rd_sermatic" Content="{DynamicResource SI}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" Width="100"
HorizontalAlignment="Left" IsChecked="{Binding SERMATIC}" GroupName="stkS" Panel.ZIndex="13" TabIndex="14" />
<RadioButton x:Name="rd_sermaticNO" Content="{DynamicResource NO}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" Width="100"
HorizontalAlignment="Left" GroupName="stkN"
Panel.ZIndex="14" TabIndex="15" />
</StackPanel>
</dxlc:LayoutItem>
<dxlc:LayoutItem >
<!--<dxe:ComboBoxEdit EditValue="{Binding SERMATICCOM}"/>-->
<UniformGrid Rows="1" Columns="2" DockPanel.Dock="Top" Margin="4,0,4,4" IsEnabled="{Binding IsChecked, ElementName=rd_sermatic}">
<TextBlock Margin="0" TextWrapping="Wrap" Text="{DynamicResource PortaCOM}" TextAlignment="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
<ComboBox x:Name="cmb_SERMATICCOM" Height="23" Margin="10,2,0,0" Panel.ZIndex="15" TabIndex="16">
<ComboBoxItem Content="COM1" />
<ComboBoxItem Content="COM2" />
<ComboBoxItem Content="COM3" />
<ComboBoxItem Content="COM4" />
<ComboBoxItem Content="COM5" />
<ComboBoxItem Content="COM6" />
<ComboBoxItem Content="COM7" />
<ComboBoxItem Content="COM8" />
</ComboBox>
</UniformGrid>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxlc:LayoutControl>
</StackPanel>
</UserControl>
Where are my error(s)?
I have this XAML code:
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title}" Width="200" />
<TextBox Text="{Binding Body}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The controls are binded using the MVVM pattern. The user can change the content of the two text boxes. Is there a possible way to get the updated text from these text boxes at some point when I need them?
Your ViewModel should implement INotifyPropertyChanged and Use TwoWay Binding as below
<ListView Name="ListBoxWithNews" ItemsSource="{Binding News,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding imageURL,Mode=TwoWay}" Width="75" Height="75" />
<StackPanel>
<TextBox Text="{Binding Title,Mode=TwoWay}" Width="200" />
<TextBox Text="{Binding Body,Mode=TwoWay}" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I am making an application in which I want to resize screen area when keyboard is open. Just like in this calendar application of windows phone.
After opening keyboard look screen should resize and also I should be able to scroll till the end of the page without closing keyboard:
In my application i am not able to do these things. In my page last elements of the page stays behind keyboard if i want to access that elements of the page i have to close keyboard but in calendar application of Nokia does great job by re sizing the page somehow so i can access whole part of page even though keyboard is open.
Can somebody help me out in this problem?
Here is code for my page
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Style="{StaticResource HeaderStackPanelStyle}">
<TextBlock TextAlignment="Center" Style="{StaticResource PhoneTextBlockHeaderStyle}" Text="Add Claim Item" />
</StackPanel>
<ScrollViewer Name="MainPageScroller" Grid.Row="1">
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Margin="12,0,12,12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Name="MainContentPenal" Grid.Row="0">
<StackPanel >
<TextBlock TextAlignment="Left" Text="Category" Style="{StaticResource PhoneTextFirstItemStyle}" >
</TextBlock>
<ToolKit:ListPicker x:Name="CategoryListPicker"
ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedCategory, Mode=TwoWay}" SelectedIndex="{Binding Categories,Converter={StaticResource DefaultSetter}}"
ExpansionMode="FullScreenOnly" SelectionMode="Single" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" SelectionChanged="CategorySelection" ItemTemplate="{StaticResource CategoryTamplate}" FullModeItemTemplate="{ StaticResource CategoryTamplate}" >
</ToolKit:ListPicker>
</StackPanel >
<StackPanel Visibility="{Binding SelectedCategory, Converter={StaticResource TravelMileageHelper}, ConverterParameter=amount}" >
<TextBlock TextAlignment="Left" Text="Amount" Style="{StaticResource PhoneTextFirstItemStyle}" />
<TextBox x:Name="AmountTextBox" Style="{StaticResource WebExpensesTextBoxStyle}" Text="{Binding Amount, Mode=TwoWay}" KeyUp="numericTextBox_keyUp" KeyDown="numericTextBox_keyDown" InputScope="Number" TextChanged="TextChange_Event" />
</StackPanel>
<StackPanel Visibility="{Binding SelectedCategory, Converter={StaticResource TravelMileageHelper},ConverterParameter=mileage}" >
<TextBlock TextAlignment="Left" Text="Mileage units" Style="{StaticResource PhoneTextFirstItemStyle}" />
<TextBox x:Name="mileageTextBox" Text="{Binding MileageUnit, Mode=TwoWay}" Style="{StaticResource WebExpensesTextBoxStyle}" KeyUp="numericTextBox_keyUp" KeyDown="numericTextBox_keyDown" TextWrapping="Wrap" InputScope="Number" TextChanged="TextChange_Event"/>
</StackPanel>
<StackPanel Visibility="{Binding SelectedCategory, Converter={StaticResource TravelMileageHelper}, ConverterParameter=trip}" >
<TextBlock TextAlignment="Left" Text="Mileage" Style="{StaticResource PhoneTextFirstItemStyle}" />
<Button Content="Add mileage" Click="AddMileage"/>
</StackPanel>
<StackPanel Visibility="{Binding SelectedCategory,Converter={StaticResource TravelMileageHelper}, ConverterParameter=trip}" >
<StackPanel Visibility="{Binding TripMasterModel, Mode=TwoWay, Converter={StaticResource VisibiltyHelper}}">
<Grid DataContext="{Binding TripMasterModel}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Left" Margin="5 0 0 0" VerticalAlignment="Center" Text="{Binding Start}"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="" FontFamily="Segoe UI Symbol" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="2">
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding End}"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="3">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Distance}"/>
</StackPanel>
<StackPanel Visibility="{Binding subTrips,Converter={StaticResource VisibiltyHelper}}" Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="4" >
<TextBlock HorizontalAlignment="Left" Text="via"/>
<ItemsControl ItemsSource="{Binding subTrips}" ItemTemplate="{StaticResource SubTripTemplate}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Grid>
</StackPanel>
</StackPanel>
<StackPanel >
<TextBlock TextAlignment="Left" Text="Description" Style="{StaticResource PhoneTextFirstItemStyle}" />
<TextBox x:Name="DescriptionTextBox" Style="{StaticResource WebExpensesTextBoxStyle}" Text="{Binding Description, Mode=TwoWay}" Height="120" TextWrapping="Wrap" TextChanged="TextChange_Event" KeyDown="DescriptionTextBox_KeyDown"/>
</StackPanel>
<StackPanel >
<ToolKit:DatePicker HeaderTemplate="{StaticResource DatePickerHeader}" Value="{Binding SelectedDate,Mode=TwoWay}" ValueStringFormat="{Binding DateFormat}" HorizontalAlignment="Left" x:Name="DatePicker" VerticalAlignment="Top" Width="200" />
</StackPanel>
<StackPanel Visibility="{Binding Currencies, Converter={StaticResource VisibiltyHelper}}" >
<TextBlock TextAlignment="Left" Text="Currency" Style="{StaticResource PhoneTextFirstItemStyle}" />
<ToolKit:ListPicker x:Name="CurrencyListPicker"
ItemsSource="{Binding Currencies}" SelectedItem="{Binding SelectedCurrency, Mode=TwoWay}"
DisplayMemberPath="Name" SelectedIndex="{Binding Currencies,Converter={StaticResource DefaultSetter}}" FullModeItemTemplate="{ StaticResource CurrencyTamplate}" >
</ToolKit:ListPicker>
</StackPanel>
<StackPanel Visibility="{Binding Clients, Converter={StaticResource VisibiltyHelper}}" >
<TextBlock TextAlignment="Left" Text="Client" Style="{StaticResource PhoneTextFirstItemStyle}"/>
<ToolKit:ListPicker x:Name="ClientListPicker"
ItemsSource="{Binding Clients}" SelectedItem="{Binding SelectedClient, Mode=TwoWay}"
ItemTemplate="{StaticResource ShowMember}" SelectedIndex="{Binding Clients,Converter={StaticResource DefaultSetter}}" FullModeItemTemplate="{ StaticResource ClientTemplate}" >
</ToolKit:ListPicker>
</StackPanel>
<StackPanel Visibility="{Binding SubClients, Converter={StaticResource VisibiltyHelper}}" >
<TextBlock TextAlignment="Left" Text="Subclient" Style="{StaticResource PhoneTextFirstItemStyle}"/>
<ToolKit:ListPicker x:Name="SubClientListPicker"
ItemsSource="{Binding SubClients,Mode=TwoWay}"
DisplayMemberPath="Name" SelectedItem="{Binding SelectedSubclient, Mode=TwoWay}" SelectedIndex="{Binding SubClients,Converter={StaticResource DefaultSetter},Mode=TwoWay}" FullModeItemTemplate="{ StaticResource ClientTemplate}" >
</ToolKit:ListPicker>
</StackPanel>
<StackPanel Visibility="{Binding Vendors, Converter={StaticResource VisibiltyHelper}}" >
<TextBlock TextAlignment="Left" Text="Vendor" Style="{StaticResource PhoneTextFirstItemStyle}"/>
<ToolKit:ListPicker x:Name="VendorListPicker"
ItemsSource="{Binding Vendors}" SelectedItem="{Binding SelectedVendor, Mode=TwoWay}"
DisplayMemberPath="Name" SelectedIndex="{Binding Vendors,Converter={StaticResource DefaultSetter}}" SelectionChanged="vendorSelection" FullModeItemTemplate="{ StaticResource ClientTemplate}" >
</ToolKit:ListPicker>
</StackPanel>
<StackPanel >
<TextBlock TextAlignment="Left" Text="Receipt" Style="{StaticResource PhoneTextFirstItemStyle}"/>
<Button Click="AddReceipt_Btn_Click" Content="Add receipt"/>
</StackPanel>
<StackPanel x:Name="ImagePenal">
<ItemsControl Width="Auto" HorizontalAlignment="Stretch" ItemsSource="{Binding ReceiptList}" ItemTemplate="{StaticResource ImageListTemplate}" >
</ItemsControl>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
Give your content in between ListBox or ScrollViewer.
<ListBox>
//your textbox and everything
</ListBox>
or
<ScrollViewer>
//your textbox and everything
</ScrollViewer>
I have a ComboBox that has an ItemTemplate with a CheckBox in it (read Dropdown CheckBoxList). I basically want to have a separate binding for the text in the combobox (both when an item is selected, and if an item isn't selected). I've tried a few different methods but either can't seem to get them to work with my setup, or can't find they have some issues. I've even tried a few mixes and matches of them. Usually I find they either don't work when an item isn't specifically selected (which could be possible if the user checks a few boxes then clicks out of the ComboBox), or aren't updating the text properly.
My xaml is this (the items of focus are the DataTemplates with the ComboBoxes in them):
<UserControl x:Class="BestClient.ucReportViewer"
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:BestClient"
mc:Ignorable="d"
d:DesignHeight="315" d:DesignWidth="388" Background="#FFD7DFEC">
<UserControl.Resources>
<DataTemplate x:Key="datetime">
<StackPanel Orientation="Horizontal" Height="35">
<TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" />
<DatePicker Tag="{Binding rfParameter}" SelectedDate="{Binding rfValues, Mode=TwoWay}" Width="200" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="office">
<StackPanel Orientation="Horizontal" Height="35">
<TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" />
<ComboBox x:Name="officeComboBox" Tag="{Binding rfParameter}" Width="200" ItemsSource="{Binding Path=DataContext.OfficeList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Tag="{Binding id}" IsChecked="{Binding isSelected}" Width="200" Content="{Binding value}" Margin="2" x:Name="CheckBox" Checked="OfficeCheckBox_Checked"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="carrier">
<StackPanel Orientation="Horizontal" Height="35">
<TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" />
<ComboBox Tag="{Binding rfParameter}" Width="200" ItemsSource="{Binding Path=DataContext.CarrierList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Tag="{Binding id}" IsChecked="{Binding isSelected}" Width="200" Content="{Binding value}" Margin="2"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="defaultTemplate">
<StackPanel Orientation="Horizontal" Height="35">
<TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" />
<TextBox Tag="{Binding rfParameter}" Width="200" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
<local:ReportFilterTemplateSelector x:Key="ReportFilterTemplateSelector" />
</UserControl.Resources>
<Grid x:Name="ReportViewer">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="45"/>
<RowDefinition Height="*"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Viewbox Grid.Row="0" Grid.Column="0">
<TextBlock Margin="10" TextWrapping="Wrap" Text="Select a Report:"/>
</Viewbox>
<ComboBox Grid.Column="1" Margin="10" Grid.ColumnSpan="2" ItemsSource="{Binding ReportList}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedItem="{Binding SelectedReport}" VerticalContentAlignment="Center" />
<ListView x:Name="FilterList" Margin="10,0" Grid.Row="1" Grid.ColumnSpan="3" ItemTemplateSelector="{StaticResource ReportFilterTemplateSelector}" ItemsSource="{Binding reportFilters, Mode=TwoWay}" />
<Button Command="{Binding OpenReport}" Content="Open Report" Grid.Column="2" Margin="10" Grid.Row="2" VerticalAlignment="Stretch"/>
</Grid>
</UserControl>
Ideally, I'd like to bind the display text of the combobox with the OfficeListValues method in my ViewModel.
{Binding Path=DataContext.OfficeListValues, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}
Any help would be appreciated!