Get selected item on expanderView - c#

I'm using a ExpanderView to display some data in my app. But I'm having some difficulty trying to find out how to get an ExpanderViewItem's data after it's been selected.
On a ListBox you can call SelectionChanged="yourFunction" in your xaml code.. but for the expanderview I have no idea how to do this?
This is my XAML code for the expander:
<!--Custom header template-->
<DataTemplate x:Key="CustomHeaderTemplate">
<TextBlock Text="" FontSize="28" />
</DataTemplate>
<!--Custom expander template-->
<DataTemplate x:Key="CustomExpanderTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Width="400" Height="60" Fill="#FFF1F1F1" HorizontalAlignment="Stretch" StrokeThickness="0" Grid.Row="0" Grid.Column="0" />
<TextBlock Text="{Binding procedureName}" FontSize="30" Foreground="#FF00457C" FontWeight="Normal" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="10,0,0,0" />
</Grid>
</DataTemplate>
<!--Custom expander items template-->
<DataTemplate x:Key="ExpanderViewItems" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="15" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding flagIcon}" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" />
<TextBlock FontSize="26" Text="{Binding N}" Foreground="Black" FontWeight="Normal" Grid.Row="0" Grid.Column="1"/>
<TextBlock FontSize="20" Text="{Binding RNG}" Foreground="Black" FontWeight="Normal" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2"/>
<TextBlock FontSize="26" Text="{Binding ValueAndUnit}" Foreground="Black" FontWeight="Medium" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
<TextBlock FontSize="18" Text="{Binding COM}" Foreground="Black" FontWeight="Normal" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" TextWrapping="Wrap" />
<Line StrokeThickness="1" Stroke="#C4C6CC" Stretch="Fill" X1="0" X2="1" Y1="0" Y2="0" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" />
</Grid>
</DataTemplate>
<!--Listbox Containing ExpanderViews-->
<ListBox Name="testsList" Grid.Row="3" Grid.Column="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<!--ExpanderView-->
<toolkit:ExpanderView Header="{Binding}"
HeaderTemplate="{StaticResource CustomHeaderTemplate}"
Expander="{Binding}"
ExpanderTemplate="{StaticResource CustomExpanderTemplate}"
x:Name="expander"
FontSize="36"
Foreground="#FF00457C"
ItemsSource="{Binding testItems}"
ItemTemplate="{StaticResource ExpanderViewItems}" >
</toolkit:ExpanderView>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I'd really appreciate any help in the right direction! This seems to be a question that is not easily answered around the web.

#Frederik I've implemented what you've done in the code above using the SelectionChanged event of the ListBox - it still works fine for me.
I've been banging my head against the wall for a bit, but finally managed to solve it. First of all for the ItemTemplate I've made sure that the template is placed in a ListBoxItem element as it follows:
<DataTemplate x:Key="ExpanderViewItems" >
<ListBoxItem DataContext="{Binding}" Tap="ListBoxItem_Tap_1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="15" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding flagIcon}" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" />
<TextBlock FontSize="26" Text="{Binding N}" Foreground="Black" FontWeight="Normal" Grid.Row="0" Grid.Column="1"/>
<TextBlock FontSize="20" Text="{Binding RNG}" Foreground="Black" FontWeight="Normal" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2"/>
<TextBlock FontSize="26" Text="{Binding ValueAndUnit}" Foreground="Black" FontWeight="Medium" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
<TextBlock FontSize="18" Text="{Binding COM}" Foreground="Black" FontWeight="Normal" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" TextWrapping="Wrap" />
<Line StrokeThickness="1" Stroke="#C4C6CC" Stretch="Fill" X1="0" X2="1" Y1="0" Y2="0" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" />
</Grid>
</ListBoxItem>
</DataTemplate>
Once this is in place, go in the code behind and in the Tap event declared for the ListBoxItem use something like this:
ListBoxItem item = sender as ListBoxItem;
ExpanderItemModel model = item.DataContext as ExpanderItemModel;
Of course, ExpanderItemModel will be whatever you're using for your expander items...
This worked fine for me
Hope this helps!
Good luck!

You can use the "tap" event on the listbox:
In your XAML file add a tap event listner:
<!--Listbox Containing ExpanderViews-->
<ListBox Name="testsList" Grid.Row="3" Grid.Column="0" Tap="testsList_Tap" >
<ListBox.ItemTemplate>
<DataTemplate>
<!--ExpanderView-->
<toolkit:ExpanderView Header="{Binding}"
...
In your code behind file, implement the tap handler:
private void testsList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
someModel selectedItem = (someModel)this.testsList.SelectedItem;
// Do something with your seleted data
...
}

you can get the selected values by listbox selectionchanged or expanderview expanded events.
For listbox :
private void lstExams_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
Model.ExamTitles data = (sender as ListBox).SelectedItem as Model.ExamTitles;
}
}
Here ExamTitles is a class which contains collections
For expanderview Expanded
private void ExpanderView_Expanded(object sender, RoutedEventArgs e)
{
ExpanderView expview = (sender as ExpanderView);
Model.ExamTitles data = expview.Header as Model.ExamTitles;
}
Hope this helps!

Related

How to move focus with in columns inside one grid cell

I have grid designed something like below:
This is xaml used for a grid:-
I am using devexpress gridcontrol in my application.
<dxg:GridControl ItemsSource="{Binding MyAddresses}">
<dxg:GridControl.View>
<dxg:TableView NavigationStyle="Cell"></dxg:TableView>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn Name="MyAddress" Header="Address" MinWidth="725">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Grid DataContext="{Binding RowData.Row}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition MinWidth="250"></ColumnDefinition>
<ColumnDefinition Width="25"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition MinWidth="250"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Text="Address"/>
<dxe:TextEdit Grid.Row="0" TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top" Grid.RowSpan="3" Grid.Column="2" MaxLength="2000" VerticalAlignment="Stretch" Text="{Binding PostAddress}"/>
<TextBlock Grid.Row="6" Grid.Column="0" Text="Country" />
<dxe:TextEdit Grid.Row="6" Grid.Column="2" Text="{Binding PostCountry}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="City" />
<dxe:TextEdit Grid.Row="4" Grid.Column="2" MaxLength="100" Text="{Binding City}"/>
<TextBlock Grid.Row="8" Grid.Column="0" Text="Postal Code" />
<dxe:TextEdit Grid.Row="8" Grid.Column="2" MaxLength="15" Text="{Binding PostalCode}"/>
<TextBlock Grid.Row="10" Grid.Column="0" Text="Subdivision" />
<dxe:TextEdit Grid.Row="10" Grid.Column="2" MaxLength="100" Text="{Binding Subdivision}"/>
<TextBlock Grid.Row="0" Grid.Column="4" Text="Email" />
<dxe:TextEdit Grid.Row="0" Grid.Column="6" MaxLength="254" Text="{Binding Email1}"/>
<TextBlock Grid.Row="2" Grid.Column="4" Text="Phone" />
<dxe:TextEdit Grid.Row="2" Grid.Column="6" MaxLength="20" Text="{Binding Phone1}"/>
<TextBlock Grid.Row="4" Grid.Column="4" Text="Phone" />
<dxe:TextEdit Grid.Row="4" Grid.Column="6" MaxLength="20" Text="{Binding Phone2}"/>
<TextBlock Grid.Row="6" Grid.Column="4" Text="Fax" />
<dxe:TextEdit Grid.Row="6" Grid.Column="6" MaxLength="50" Text="{Binding Fax1}"/>
<TextBlock Grid.Row="8" Grid.Column="4" Text="Telex" />
<dxe:TextEdit Grid.Row="8" Grid.Column="6" MaxLength="100" Text="{Binding Telex}"/>
<TextBlock Grid.Row="10" Grid.Column="4" Text="Web" />
<dxe:TextEdit Grid.Row="10" Grid.Column="6" MaxLength="255" Text="{Binding Web}"/>
</Grid>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn FieldName="NewField"/>
</dxg:GridControl.Columns>
</dxg:GridControl>
In first cell I have few columns, I want to move cursor with in first cell and then jump to second cell.
Can someone please help.
![enter image description here][1]
My grid looks like above. I have focus on first field . On pressing tab I want focus move to City field not to next cell which is New Field.
Any suggestions?
[1]: http://i.stack.imgur.com/ENqqP.png
The same issue is already discussed at DevExpress Support Center: Tabbing issue in CellTemplate. Thus, you can use the solution provided by the DevExpress Support Team.
The main idea of this solution is in custom handling of the TabbedView.PreviewKeyDown event:
void TableView_PreviewKeyDown(object sender, KeyEventArgs e) {
if (e.Key == Key.Tab) {
// do some custom handling
e.Handled = true; // avoid TabbedView's default focus processing
}
}

Data Grid Template [WPF]

how this type of data grid template can be created??
i can't find any way to make this template.
or can u suggest other way??
i.e. grid view or so and how!
The last column are not required as of now.
CodeBehind:
var pp = from asd in db.OrderMasters
select new
{
asd.CFN,
asd.Location,
asd.CreatedOn,
asd.Quantity
};
dgOrderMaster.ItemsSource = pp.ToList();
Markup:
<DataGrid x:Name="dgOrderMaster" HorizontalContentAlignment="Center" BorderThickness="1" Margin="10" Grid.Row="3">
i worked around, and found listview is way more helpfull for my task,
Here's the markup:
<ListView Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="3" Background="{x:Null}">
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="0" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="4" Background="White">
<Grid Background="White" Margin="0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Margin="50,5" >
<TextBlock Text="Customer" Foreground="#33B6EF" FontSize="20" />
<TextBlock Text="{Binding cust}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="1">
<TextBlock Text="Location" Foreground="#33B6EF" FontSize="20" />
<TextBlock Text="{Binding loc}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="2">
<TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />
<TextBlock Text="{Binding con}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="3">
<TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" />
<TextBlock Text="{Binding quant}" FontSize="20" />
</StackPanel>
</Grid>
<Border.Effect>
<DropShadowEffect BlurRadius="5" ShadowDepth="5" />
</Border.Effect>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Image in DataTemplate from Url\Device

I have this DataTemplate in my ListBox:
<local:SearchTemplateSelector.VideoTemplate>
<DataTemplate>
<Grid>
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="Black" Opacity="0.3" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Margin="0" HorizontalAlignment="Left" Source="{Binding Path=ImgUrl}" Width="100" Height="100" />
<Grid Grid.Column="1" Margin="10,0,8,0">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Name}" FontSize="20" Foreground="Black" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<StackPanel Orientation="Horizontal" Margin="0,-5,0,0" Grid.Row="1">
<TextBlock Text="Views: " FontSize="20" Foreground="Black"/>
<TextBlock Text="{Binding ViewCount}" FontSize="20" Foreground="Black"/>
</StackPanel>
<TextBlock Text="{Binding TimeStr}" FontSize="20" Foreground="Black" Grid.Row="2" Margin="0,0,0,0" />
</Grid>
</Grid>
</Grid>
</DataTemplate>
</local:SearchTemplateSelector.VideoTemplate>
Now i have Image that i binding from ImgUrl of my object.And i want to know if there is possibility to make something like this:
If the image is in the device take it from the device,if not download it and save it on the device for next time, every image have a unique id so i can just save it with id.png
If I understand you correct, you have to add logic to ImgUrl property. You have to add some method in Set{}, which will try load image from isolatedStorage, and catch exception, in which it will use method to load and save image to isolatedStorage.

Access and modify properties of grid row within data template

I have difficulty accessing a grid or its rows(within a ListBox), despite defining the grid's or row's name. I intend to set a new MaxHeight to one of its rows when some parameter is passed in from a SharePoint browsable property to the Silverlight control.
How may i achieve the desired effect? Binding perhaps?
# Page.xaml:
<ListBox ItemsSource="{Binding}" DataContext="" x:Name="NewsList" SelectionChanged="NewsList_SelectionChanged" SelectionMode="Single" Width="580" Height="360" VerticalAlignment="Top" HorizontalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate >
<Grid Height="110" Width="540" x:Name="StaffNewsBodyHeight">
<Grid Height="110" Width="540">
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="{Binding StaffNewsBodyHeight}" />
<RowDefinition Height="15" />
</Grid.RowDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="82" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border CornerRadius="2" BorderThickness="2" BorderBrush="Gray" Height="82" Width="82" Background="LemonChiffon" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.RowSpan="3" Grid.Column="0" >
<Image Source="{Binding NewsThumbnail}" Style="{StaticResource ThumbNailPreview}" />
</Border>
<TextBlock x:Name="NewsTitle" FontFamily="Arial" FontWeight="bold" TextDecorations="Underline" Text="{Binding Title}" Style="{StaticResource TitleText}" Grid.Row="0" Grid.Column="1"/>
<TextBlock x:Name="NewsBody" FontFamily="Arial" Text="{Binding NewsBody}" Margin="5" Style="{StaticResource DescriptionBlock}" Grid.Row="1" Grid.Column="1" />
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="3,3,3,3">
<TextBlock Text="Published By:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
<TextBlock Text="{Binding PublishedBy}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
<TextBlock Text="{Binding DatePublished}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
# Page.xaml.cs:
if (!string.IsNullOrEmpty(_setLength))
{
StaffNews test = new StaffNews();
//assign new height to gridrow of NewsBody
if (_setLength.Contains("_3"))
test.StaffNewsBodyHeight.Equals(200);
}
I believe that StaffNews is representing one item in your list, right?
In that case, to assign a value to a property, use:
test.StaffNewsBodyHeight = 200;
to replace the last line of your snippet.
[P.S. - StaffNewsBodyHeight is a dependency property defined in StaffNews, right?]

User Control Not Rendering When Used as a DataTemplate?

I have a usercontrol which I want to use as a DataTemplate in a Listbox.
This works:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If I put the exact same code from between the <DataTemplate> tags:
<UserControl x:Class="CandiMan.View.CandidatePresentationControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cm="clr-namespace:CandiMan;assembly=CandiMan"
xmlns:vw="clr-namespace:CandiMan.View;assembly=CandiMan"
xmlns:vm="clr-namespace:CandiMan.ViewModel;assembly=CandiMan"
Height="100" Width="880" BorderBrush="Black" BorderThickness="1">
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</UserControl>
into a usercontrol named CandidatePresentationControl and do it like
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
it does not get rendered. No errors, just an empty listbox. Can someone help me??
Thank you!
edit: I forgot something, dunno if it matters: The whole thing I'm doing this in, is a usercontrol, too.
It shouldn't matter, that your referenced UserControl is within another UserControl. Try these steps to better debug your XAML-code: http://beacosta.com/blog/?p=52
Since you have your data hard wired in XAML, the only way to explain the empty ListBox is, that your UserControl can't be found by the parent UserControl, imo.
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl DataContext="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You have to write this way in order to bind datacontext, I would suggest you look at MVVM that will give you idea on how to do it even better way.

Categories

Resources