Binding in DataTemplate WPF

Hi everyone,
I'm now making a simple File Manager app. My application contains a ListBox whose ItemsSource={Binding FileList}
Each item of my listBox is defined with custom item template which is used for displaying the status of file
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="23">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="23"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Stretch="Fill"/>
<TextBlock Margin="10, 0, 0, 0"
Text="{Binding LastModified}"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Grid.Column="1"/>
</DataTemplate>
</ListBox.ItemTemplate>
As you see, each item has an Image . I want that Image to be displayed as Locked if 2 conditions are satisfied : DateTime.Now - LastModified < 60 and Path is exists
(LastModified and Path are property of FileList) . I'm thinking about MultiBinding but tried so many time with failure 
Can anyone help me please ? 
Thank you

You could use a converter and a DataTrigger that sets some property of the Image (Source or Opacity for example) based on whether the condition is true or false:
namespace WpfApplication22
class CustomConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
FileList item = value as FileList;
if (item != null && string.IsNullOrEmpty(item.Path) && System.IO.File.Exists(item.Path) && (DateTime.Now.Date.Subtract(item.LastModified.Date).TotalDays < 60))
return true;
return false;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
throw new NotImplementedException();
<ListBox ItemsSource="{Binding FileList}" xmlns:local="clr-namespace:WpfApplication22">
<ListBox.Resources>
<local:CustomConverter x:Key="conv"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="23">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="23"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Stretch="Fill" >
<Image.Style>
<Style TargetType="Image">
<Setter Property="Source" Value="av1.png"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=., Converter={StaticResource conv}}" Value="True">
<Setter Property="Opacity" Value="0.5"/>
<!-- or set the source -->
<!--<Setter Property="Source" Value="locked.png"/>-->
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Margin="10, 0, 0, 0" Text="{Binding LastModified}" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
There is no reason to use a multi-converter here since you can bind to the FileList (or whatever your class is called) itself as shown in the above sample code.
Hope that helps.
Please remember to close your threads by marking helpful posts as answer.

Similar Messages

  • WPF Binding XML in Oracle

    Hi,there,I'm using WPF Binding a xml file which stored in Oracle,My question is:is there a way to Bind XML to WPF control directly? If it has,do this way as useful as Bind a data instance?
    Thanks

    You not given that much info...but anyway
    does the following help?
    http://stackoverflow.com/questions/3399338/wpf-bind-a-listview-to-oracle-data-source

  • How to enter a value into datagrid cell in wpf through manually?

    Hi,
        Here my datagrid rows are in readonly mode here how can i enter the values in to the datagrid cell.(means how can i edit the cell value).i am adding the value to datagrid through programetically, I think  for this reason my datagrid rows
    are visible in readonly mode. Then how can i edit. Please guide me.
    Regards,
    Bhadram

    Hi Barry,
       Thank you for your reply, Now i sending my sample please check it once and suggest me.
    MainWindow.xaml.cs
    private void Save_Click(object sender, RoutedEventArgs e)
     List<CustomerMainViewModel> customer = new List<CustomerMainViewModel>(); customerviewmodel.NameTextField = tbName.Text;
    customerviewmodel.AddressTextField = tbAddress.Text;
    customerviewmodel.CountryField = countryddl.Text;
    customerviewmodel.StateField = stateddl.Text;
    customerviewmodel.Product = customerviewmodel.Product1 + "," + customerviewmodel.Product2;
    foreach(string str in customerviewmodel.actionCollection)
    customerviewmodel.ActionColl.Add(str);
    customerviewmodel.actionCollection.Clear();
    customer.Add(customerviewmodel);
    dataGrid1.Items.Add(customer);
    MessageBox.Show("Data Successfully Saved", " MessageBox", MessageBoxButton.OK, MessageBoxImage.Asterisk);
    clearValues();
    MainWindow.xaml
    <DataGrid
    Height="144"
    HorizontalAlignment="Left"
    Margin="79,447,0,0"
    Name="dataGrid1"
    VerticalAlignment="Top" CanUserAddRows="True"
    Width="399" Grid.RowSpan="2" IsReadOnly="False">
    <DataGrid.Columns>
    <DataGridTextColumn Header="NAME" Binding="{Binding NameTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False" />
    <DataGridTextColumn Header="ADDRESS" Binding="{Binding AddressTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="GENDER" Binding="{Binding GenderField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="COUNTRY" Binding="{Binding CountryField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="STATE" Binding="{Binding StateField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="PRODUCT" Binding="{Binding Product,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTemplateColumn Header="ACTION" MinWidth="140" IsReadOnly="False">
    <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <ComboBox x:Name="actionddl" ItemsSource="{Binding ActionColl}"/>
    </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    </DataGrid.Columns>
    </DataGrid>
    In the above "xaml" file i am using the attribute "Readonly="False"" but its not effected on my code still my datagrid is in readonly mode, i don't know why it happens. 
    And I am adding data to my datagrid through "Wpf controls (TextBox,CheckBox,ComboBox and etc...)"  while click on "save" button the data added to grid. adding to grid works properly but the entire row is in readonly mode. How can
    i solve my problem.  

  • Windows Phone DataTemplate

    Hi,
    I am new in Windows Phone development, I have a listbox with a datatemplate, in the datatemplate there is a textblock named mytextblock, I can not access the textblock by using the name in MainPage.xaml.cs. But I want to change the forebackground color of
    the textblock. Please help me. Sorry for my bad english.
    <ListBox Name="MyListBox">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <TextBlock Name="MyTextBlock" Text="{Binding Text}"/>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

    Hi frrey gdfkaj,
    >>I can not access the textblock by using the name in MainPage.xaml.cs.
    Yes, we can not access the textblock control which are in the DataTemplate by using its name in code behide. But we can use the
    VisualTreeHelper to help us find the textblock control.
    For the detailed information, please try to refer to my reply in this thread:
    https://social.msdn.microsoft.com/Forums/en-US/4b7f99f2-a468-4a7e-8f54-2d8c54af6e7d/how-to-access-the-texblocks-in-a-listbox?forum=wpdevelop
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • [WPF] Format column text for showing percentage

    Hi,
    in one column of my DataGrid I show percentage values.
    From database, I get the number:
    - in view, I would concatenate the char "%"
    - in edit, the user add his value and when mouse leaves cell automatically is concatenated the char "%"
    How can I implement it?
    Thanks.

    Replace any DataGridTextColumn with a DataGridTemplateColumn and specify a StringFormat for the TextBlock in the CellTemplate only:
    <DataGrid.Columns>
    <!--<DataGridTextColumn Binding="{Binding Val, StringFormat=P}"/>-->
    <DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Val, StringFormat='\{0\}%'}"/>
    </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
    <TextBox Text="{Binding Val}"/>
    </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
    </DataGridTemplateColumn>
    </DataGrid.Columns>
    Note that the "number" source property must be an int, double, decimal etc. for the StringFormat to get applied.
    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question.

  • Unexpected InvalidCastException With DataTemplate

    I have the following Xaml for which I set the ItemsSource property as follows:
    <ItemsControl x:Name="itmRecipients" Grid.Column="0" Grid.Row="2" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Auto" ScrollViewer.BringIntoViewOnFocusChange="True">
    <ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate><DataTemplate><RadioButton Style="{StaticResource BasicToggleButton}" GroupName="Recipients" Checked="Recipient_Checked" Content="{Binding Name}" Tag="{Binding Index}"/></DataTemplate></ItemsControl.ItemTemplate>
    </ItemsControl>
    Me.itmRecipients.ItemsSource = Me.Recipients.Select(Function(r, i) New With {.Name = r.Name, .Index = i})
    As you can see, the DataTemplate is just a RadioButton which uses the Name and Index properties of the bound items. The bound items are an anonymous type with the properties Name and Index. But when I run the code, I get the following error:
    A first chance exception of type 'System.InvalidCastException' occurred in GiftTrackerUnivAppTest_Windows.exe
    After looking at App.g.i.vb, I found the following in unhandledExceptionArgs:
    "System.InvalidCastException: Unable to cast object of type 'VB$AnonymousType_0`2[System.String,System.Int32]' to type 'Windows.UI.Xaml.Controls.RadioButton'.
        at GiftTrackerUnivAppTest_Windows.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e)"
    'VB$AnonymousType_0`2[System.String,System.Int32]' is obviously my anonymous type with the Name and Index properties. Why is it trying to convert my anonymous type to a RadioButton instead of applying it to the DataTemplate? Thanks.
    Nathan Sokalski [email protected] http://www.nathansokalski.com/

    Hi Nathan,
    I used the following code snippet to test in store app, but I worked. I could not reproduce your problem. Can you post a repro project or post more information to explain your scenario?
    Private Sub Page_Loaded(sender As Object, e As RoutedEventArgs)
    list = New System.Collections.ObjectModel.ObservableCollection(Of Employee)()
    Dim rnd As New Random()
    For i As Integer = 0 To 99
    Dim ee As New Employee()
    ee.Name = "herro" & i.ToString()
    ee.Index = rnd.Next(0, 101)
    list.Add(ee)
    Next
    itmRecipients.ItemsSource = list.Where(Function(w) w.Index > 10).[Select](Function(s) New With { _
    Key .Name = s.Name, _
    Key .Index = s.Index _
    End Sub
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate
    the survey.

  • CrystalReportViewer WPF

    How can I bind the CrystalReportViewer (WPF) with a MemoryStream or a ByteArray ?
    In our applicantion we create the report using the ExportToStream but how can we show the
    report without saving the stream in a file ?
    It seems strange that we can generate the report in a stream but we can't bind it to the viewer
    on a client application. We use the WPF Viewer.
    Thank you
    Marco

    Hello Marco
    You can not stream a report to a viewer. Your options;
    1) Stream to PDF
    2) Install CR runtime on the client, export the report on the server to a share, then view the report on the client.
    3) Use a web app
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

  • Binding richeditbox in xaml from codebehind

    Hello,
    How to bind richeditbox inside xaml. It is in datatemplate of gridview

    Yes, that's what I was working on. I have a code sample:
    MainPage.XAML.CS:
    public sealed partial class MainPage : Page
    public MainPage()
    this.InitializeComponent();
    protected override void OnNavigatedTo(NavigationEventArgs e)
    List<string> MyList = new List<string>();
    MyList.Add("A");
    MyList.Add("B");
    MyList.Add("C");
    MyList.Add("D");
    MyList.Add("E");
    MyListView.ItemsSource = MyList;
    MainPage.Xaml:
    <Page
    x:Class="REBAttachedProperty.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:REBAttachedProperty"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ListView x:Name="MyListView">
    <ListView.ItemTemplate>
    <DataTemplate>
    <RichEditBox Width="50" Height="30" local:BindableREBText.Text="{Binding}" ></RichEditBox>
    </DataTemplate>
    </ListView.ItemTemplate>
    </ListView>
    </Grid>
    </Page>
    BindableREBText.cs:
    using System;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    namespace REBAttachedProperty
    class BindableREBText
    public static DependencyProperty TextProperty = DependencyProperty.RegisterAttached(
    "Text",
    typeof(string),
    typeof(BindableREBText),
    new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnTextChanged))
    public static void SetText(RichEditBox REB, string value)
    REB.SetValue(TextProperty, value);
    public static string GetText(RichEditBox REB)
    return (string) REB.GetValue(TextProperty);
    public static void OnTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
    RichEditBox REB = sender as RichEditBox;
    string S = args.NewValue as string;
    REB.Document.SetText(Windows.UI.Text.TextSetOptions.None, S);
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with
    undefined objects and unknown namespaces.
    This is one-way binding. View Model can notify View, but View can not notify View Model.
    Do You know how to improve this code to two-way binding?

  • How to bind details list to master list

    Hello,
    I have json file with a lot objects in it. Depending on user selection object are sometimes different. For example, if user selects option #1 there are 4 objects in json string. If user selects option #2 there are 7 objects in json string. I need to update
    my UI to show selected objects. Problem is that I'm using Listbox to show items. I need Listpicker inside that listbox. Listpicker #1 should be for option #1, listpicker #2 for option #2 and so on. My question is how can I bind ItemSource to listboxes as they
    are already inside ListBox so I can't access them with code?
    Greetings.

    There's no need to access listpicker which is inside listbox, rather simply data-bind the listpickers with json data parsed.
    e.g: 
    public class OptionsClass1
    public string OptionsMainValue1 { get; set; }
    public List<string> optionSubValue1 { get; set; }
    Similarly create classes for other listpickers & databind these properties to the listpicker , therefor inside xaml, for ListPicker 1, the binding properties would be 'OptionsMainValue1' & optionSubValue1 , similarly for ListPicker 2, it would be
    'OptionsMainValue2' & 'optionsSubValue2' and so on..
    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8
    Thank you for your reply. I tried that and I end up with null exception. Here is my code:
    public class Option1
    public string MainOption1{ get; set; }
    public List<string> SubOption1{ get; set; }
    and function:
    ObservableCollection<Option1> list = new ObservableCollection<Option1>();
    private void Step2()
    var responseString = response.Content.ToString();
    JObject o = JObject.Parse(responseString);
    for (int num= 0; num< o["jsonObject"].Count(); num++)
    Option1 option1 = new Option1();
    option1.MainOption1 = "Some json string";
    option1.SubOption1.Add(option1.MainOption1);
    Listbox.ItemSource = list;
    My XAML:
    <ListBox x:Name="listbox" Margin="0,85,0,45" Background="#FFC9C9C9">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <StackPanel>
    <toolkit:ListPicker ItemsSource="{Binding SubOption1}">
    <toolkit:ListPicker.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding MainOption1}"/>
    </DataTemplate>
    </toolkit:ListPicker.ItemTemplate>
    </toolkit:ListPicker>
    </StackPanel>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

  • List of Expanders selectedItem issue

    Hi,
    In my wpf application, I have a listbox containing expanders. To implement a scenario that only one expander can be expanded at a time, I have done below binding
    <Style x:Key="LeftPanelExpanderStyle" TargetType="{x:Type Expander}">
    <Setter
    Property="IsExpanded"
    Value="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
    Suppose we have two expanders E1 and E2 in the listbox. When I expand E1, corresponding listboxitem is selected. When I expand E2 corresponding listboxitem is selected. But if I again click on E2, the listboxitem is unselected and now ListBox has no
    selection.
    Is there any way to keep the selection if the same expander is expanded and collapsed?
    I want to switch the selection only when any other expander is clicked.
    Regards,
    Sharda.

    >>But if I again click on E2, the listboxitem is unselected and now ListBox has no selection.
    Since you bind the IsExpanded property of the IsSelected property of the ListBoxItem, the IsSelected property will be set to false whenever the IsExpanded property gets set to false. This is how it works so you cannot simply use a two-way binding here.
    You could however write some code to get the desired behaviour. You could for example handle the Selected event of the ListBoxItem and the Expanded event of the Expander and set the IsSelected property and the IsExpanded property as appropriate. Here is
    an example that uses two helper methods to find the elements in the visual tree:
    <ListBox x:Name="lb">
    <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
    <EventSetter Event="Selected" Handler="lbi_Selected"/>
    </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
    <DataTemplate>
    <Expander x:Name="exp" Header="...">
    <Expander.Style>
    <Style TargetType="{x:Type Expander}">
    <EventSetter Event="Expanded" Handler="exp_Expanded"/>
    </Style>
    </Expander.Style>
    <TextBlock Text="{Binding}"/>
    </Expander>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>
    List<Expander> expanders = new List<Expander>();
    private void exp_Expanded(object sender, RoutedEventArgs e)
    Expander expander = sender as Expander;
    if (!expanders.Contains(expander))
    expanders.Add(expander);
    //select ListBoxItem
    ListBoxItem lbi = FindParent<ListBoxItem>(expander);
    lbi.IsSelected = true;
    expanders.ForEach(exp => { if (exp != expander) exp.IsExpanded = false; });
    void lbi_Selected(object sender, RoutedEventArgs e)
    //expand expander:
    Expander expander = FindChild<Expander>(sender as DependencyObject);
    expander.IsExpanded = true;
    private static T FindParent<T>(DependencyObject dependencyObject) where T : DependencyObject
    var parent = VisualTreeHelper.GetParent(dependencyObject);
    if (parent == null) return null;
    var parentT = parent as T;
    return parentT ?? FindParent<T>(parent);
    private T FindChild<T>(DependencyObject depencencyObject) where T : DependencyObject
    if (depencencyObject != null)
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depencencyObject); ++i)
    DependencyObject child = VisualTreeHelper.GetChild(depencencyObject, i);
    T result = (child as T) ?? FindChild<T>(child);
    if (result != null)
    return result;
    return null;
    You should generally not try to implement some kind of logic or behaviour in the XAML markup, that's not what it is for. You may define your bindings in the XAML markup but when you want to customize things you should implement the behaviour programmatically.
    Hope that helps.
    Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

  • Windows Phone Hub with more than 2 sections causes ArgumentException when collapsing any section

    Hi there,
    I'm working on a Universal app which is using a Hub control to display different sections.
    On startup, I want to hide some of the sections. Using a button, I want to toggle between the visible sections using a binding property on the Visibility property (Handled in the ViewModel). In my ViewModel I have 2 boolean properties that are bound to the
    corresponding sections and are converted to Visibility using a BooleanToVisibilityConverter
    <Hub>
    <HubSection>
    <DataTemplate>
    <Button Content="Test" Command="{Binding SwitchVisibilityCommand}"/>
    </DataTemplate>
    </HubSection>
    <HubSection x:Name="First" Header="Test1A" Visibility="{Binding ElementName=pageRoot,
    Path=DataContext.FirstVisibleProperty, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter} }"/>
    <HubSection x:Name="Second" Header="Test1B" Visibility="{Binding ElementName=pageRoot,
    Path=DataContext.SecondVisibleProperty, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter} }"/>
    <HubSection x:Name="Third" Header="Test2A" Visibility="{Binding ElementName=pageRoot,
    Path=DataContext.ThirdVisibleProperty, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter} }"/>
    <HubSection x:Name="Fourth" Header="Test2B" Visibility="{Binding ElementName=pageRoot,
    Path=DataContext.FourthVisibleProperty, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter} }"/>
    </Hub>
    public class MainPageViewModel : ViewModel, IMainPageViewModel
    private bool firstVisibleProperty;
    private bool secondVisibleProperty;
    public MainPageViewModel()
    FirstVisibleProperty = true;
    SecondVisibleProperty = false;
    SwitchVisibilityCommand = new DelegateCommand(ExecuteCommand);
    private void ExecuteCommand()
    FirstVisibleProperty = !FirstVisibleProperty;
    SecondVisibleProperty = !SecondVisibleProperty;
    public bool FirstVisibleProperty
    get { return firstVisibleProperty; }
    set
    firstVisibleProperty = value;
    OnPropertyChanged(() => FirstVisibleProperty);
    public bool SecondVisibleProperty
    get { return secondVisibleProperty; }
    set
    secondVisibleProperty = value;
    OnPropertyChanged(() => SecondVisibleProperty);
    public DelegateCommand SwitchVisibilityCommand { get; set; }
    This setup is working fine on Windows, but in Windows Phone I get an unhandled exception (ArgumentException with the message ´Value does not fall within the expected range.´). 
    When I reduce the amount of hubsections to two, one that is visible and one that is collapsed, everything is working fine again. When I use multiple sections that all use the the same visibility property no exception is thrown
    When I set both properties to true in the viewmodel, also no exception is thrown.
    I've also tried the following (Without succes):
    - change my boolean properties to Visibility properties
    - use different boolean properties for each of the sections
    I do not understand why this exception is thrown and the exception itself is to vague to give any useful information
    How can I resolve this error??

    I've uploaded my code to OneDrive. Use the following link to download the source:
    https://onedrive.live.com/?cid=9c0070abc26b0b55&id=9C0070ABC26B0B55%2173811

  • ListView + MVVM: How do I get the value of a selected cell?

    Hi,
    I love programming WPF using MVVM, but sometimes easy looking problems lead to unbearable suffering.
    Here is my problem: I have a simple list view with about a couple of columns. All I want to do is to copy the cell content to clipboard, when the user right-clicks on a cell.
    <ListView Grid.Row="0" ItemsSource="{Binding Articles}" SelectedItem="{Binding SelectedArticle}" SelectionMode="Single">
    <ListView.View>
    <GridView>
    <GridView.Columns>
    <GridViewColumn Header="ID" Width="70" DisplayMemberBinding="{Binding Path=ID, Mode=OneWay}" />
    <GridViewColumn Header="Name" Width="150" DisplayMemberBinding="{Binding Path=Name, Mode=OneWay}"/>
    <GridViewColumn Header="Price" Width="100" DisplayMemberBinding="{Binding Path=Price, Mode=OneWay}"/>
    <GridViewColumn Header="Description" Width="70" DisplayMemberBinding="{Binding Path=Description, Mode=OneWay}"/>
    </GridView.Columns>
    </GridView>
    </ListView.View>
    </ListView>
    Without MVVM I probably would have used the some Click-Event and extract the info from the event args. But of course I don't want to break the MVVM pattern.
    But if I use some kind of event binding I cannot find a way to retrieve event args or the sender object:
    <i:EventTrigger EventName="PreviewMouseRightButtonDown">
    <i:InvokeCommandAction Command="{Binding CopyCellValueToClipCommand}"/>
    </i:EventTrigger>
    Using this trigger I can react to the desired event, but how can I retrieve the cell value?
    I really hope you guys have a clue.
    Thanks for your help,
    Michael

    I'm not so sure about listview, I rarely use them for more complicated requirements.
    I would use a datagrid.
    You can bind a cellinfo:
    http://stackoverflow.com/questions/20080130/how-to-bind-currentcell-in-wpf-datagrid-using-mvvm-pattern
    <DataGrid AutoGenerateColumns="True"
    SelectionUnit="Cell"
    SelectionMode="Single"
    Height="250" Width="525"
    ItemsSource="{Binding Results}"
    CurrentCell="{Binding CellInfo, Mode=OneWayToSource}"/>
    and
    private DataGridCellInfo _cellInfo;
    public DataGridCellInfo CellInfo
    get { return _cellInfo; }
    set
    _cellInfo = value;
    OnPropertyChanged("CellInfo");
    MessageBox.Show(string.Format("Column: {0}",
    _cellInfo.Column.DisplayIndex != null ? _cellInfo.Column.DisplayIndex.ToString() : "Index out of range!"));
    You can use index and bind selecteditem or get contents of cell:
    public DataGridCell GetDataGridCell(DataGridCellInfo cellInfo)
    var cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
    if (cellContent != null)
    return (DataGridCell) cellContent.Parent;
    return null;
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • How to get selected item from AutoSuggestBox in Windows Phone 8.1

    In CS File "SelectedItem" is not working what is the alternative to "SelectedItem" for AutoSuggestBox in WP8.1
    In XAML File:
    <AutoSuggestBox x:Name="tblkpersonname" Width="380" Margin="0,-7,0,0" ItemsSource="{Binding}" TextChanged="tblkpersonname_TextChanged">
    <AutoSuggestBox.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Name}"
    Tag="{Binding PersonID}"/>
    </DataTemplate>
    </AutoSuggestBox.ItemTemplate>
    </AutoSuggestBox>
    In Cs File:
    private void tblkpersonname_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
    try
    if (tblkpersonname.SelectedItem != null)
    tblkdes.Text = ((values)tblkpersonname.SelectedItem).Description;
    persononlineimg.Source = new BitmapImage(new Uri(((values)tblkpersonname.SelectedItem).FlickrPersonImageUrl, UriKind.RelativeOrAbsolute));
    catch (Exception ex)
    Exceptions.SaveOrSendExceptions("Exception in tblkpersonname_SelectionChanged_1 Method In AddCast.cs file.", ex);
    Devi Prasad.P

    Hi
    Not sure about the code you have mentioned here, there is no property named selecteditem in msdn. Please refer
    https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.autosuggestbox.aspx
    <AutoSuggestBox x:Name="suggestions"HorizontalAlignment="Left" Margin="52,62,0,0"
    ItemsSource="{Binding }"VerticalAlignment="Top"
    Width="296" TextChanged="suggestions_TextChanged"
    SuggestionChosen="suggestions_SuggestionChosen"/>private void suggestions_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
                if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
                    Suggestions.Clear();
                    Suggestions.Add(sender.Text + "Tea");
                    Suggestions.Add(sender.Text + "Tatt");
    private void suggestions_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
                suggestions.Text = "Choosen";
    Something like this can be used
    Regards
    Varun Ravindranath Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you.

  • AutoSuggestBox.selecteditem is Not Working in Windows Phone8.1

    For AutoSuggestBox Selected item is Enabled in _SuggestionChosen Event But in "getitemselected()" method selected item is not working, in WP8.1
    In XAML File:
    <AutoSuggestBox x:Name="tblkpersonname" Width="380" Margin="0,-7,0,0" ItemsSource="{Binding}" TextChanged="tblkpersonname_TextChanged">
    <AutoSuggestBox.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Name}"
    Tag="{Binding PersonID}"/>
    </DataTemplate>
    </AutoSuggestBox.ItemTemplate>
    </AutoSuggestBox>
    In Cs File:
    private void tblkpersonname_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
    System.Diagnostics.Debug.WriteLine("Suggestion chosen : {0}", ((values)args.SelectedItem).Name);
    public void getitemselected()
    //Error in this line when select item from AutoSuggestBox
    if (((values)tblkpersonname.SelectedItem) != null)
    //Some Statements

    Hi chinni987,
    >>selectedItem getting null value when i selected a valu
    Have you handled the
    AutoSuggestBox.SuggestionChosen event? From your code snippets, you should have a custom class named "values", here is my completed sample, it worked well:
    <AutoSuggestBox x:Name="tblkpersonname" Width="380" ItemsSource="{Binding}" SuggestionChosen="tblkpersonname_SuggestionChosen">
    <AutoSuggestBox.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding Name}"
    Tag="{Binding PersonID}"/>
    </DataTemplate>
    </AutoSuggestBox.ItemTemplate>
    </AutoSuggestBox>
    public sealed partial class MainPage : Page
    List<values> list = new List<values>();
    public MainPage()
    this.InitializeComponent();
    this.NavigationCacheMode = NavigationCacheMode.Required;
    for (int i=0; i<10; i++ )
    list.Add(new values() { Name = "name" + (i + 1).ToString(), PersonID = i + 1 });
    this.DataContext = list;
    protected override void OnNavigatedTo(NavigationEventArgs e)
    values selectedItem = null;
    private void tblkpersonname_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
    System.Diagnostics.Debug.WriteLine("Suggestion chosen : {0}", ((values)args.SelectedItem).Name);
    selectedItem = args.SelectedItem as values;
    public void getitemselected()
    //Error in this line when select item from AutoSuggestBox
    if (selectedItem != null)
    //Some Statements
    public class values
    public string Name { get; set; }
    public int PersonID { get; set; }
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Horizontal scrolling doesn't work with ItemsStackPanel in ListView(GridView)

    Hi,
    In Win 8.1 App Store Project I have a ListView with fixed width and listen for ContainerContentChanging event because of performance issues.
    When ListView width is less than content width, horizontal scrolling doesn't work. If we change ItemsStackPanel to VirtualizingStackPanel, horizontal scrolling works fine. But ContainerContentChanging doesn't work with VirtualizingStackPanel.
    Is it possible to make horizontal scrolling work with ItemsStackPanel?
    Here simple example to reproduce this problem:
    <Page
    x:Class="App8.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App8"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
    <DataTemplate x:Key="ContinuousViewItemTemplate">
    <Border Width="800"
    Background="Green"
    Margin="10"
    Padding="5">
    <Border x:Name="root" Height="800" Background="{Binding}"/>
    </Border>
    </DataTemplate>
    <Style x:Key="ListViewStyle1" TargetType="ListView">
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Visible"/>
    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled"/>
    <Setter Property="ItemTemplate" Value="{StaticResource ContinuousViewItemTemplate}"/>
    </Style>
    </Page.Resources>
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="100"/>
    <ColumnDefinition Width="500"/>
    <ColumnDefinition/>
    <ColumnDefinition Width="500"/>
    <ColumnDefinition Width="100"/>
    </Grid.ColumnDefinitions>
    <ListView Style="{StaticResource ListViewStyle1}" Grid.Column="1">
    <SolidColorBrush Color="Red"/>
    <SolidColorBrush Color="Cyan"/>
    </ListView>
    <ListView Style="{StaticResource ListViewStyle1}" Grid.Column="3">
    <ListView.ItemsPanel>
    <ItemsPanelTemplate>
    <VirtualizingStackPanel/>
    </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <SolidColorBrush Color="Red"/>
    <SolidColorBrush Color="Cyan"/>
    </ListView>
    </Grid>
    </Page>

    Hi Mikhail Maksyuta,
    Welcome back!
    Yes, you are right! I have reproduced it on VS 2013 professional.
    I will report it as bug, Thanks for your valuable suggestions!
    If you have any other questions about this, please feel free let me know!
    Thanks again!
    Regards! 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Verizon Wirless 4GLTE for Tarboro, North Carolina Edgecombe and Rocky Mount NC Nash/Edgecombe

    Hello Verizon Wireless! Could you please tell me when the release date for 4GLTE for Tarboro and Rocky Mount which is in Edgecombe and Nash County in North Carolina? Because, 4GLTE has service in Pitt County which is the next county from us which is

  • How to add a new selection criteria in a report painter

    Hi I would like to know how to add a selection criteria in a report painter. I believe in Gen data we can add our selection criteria but my there is no option to select  company code in that. Can anyone help me in this Thanks in advance Sankar

  • BEx abap query analyzer with wrong port in url adress

    Hi Starting TA RSRT you can open ABAP WEB query in separatly browser window. For that an url adress is generated. Normaly it looks like <server>:8000/xxx. One my workstation it works well & fine. In the other hand some of our coleagues get url with a

  • Using glow in Photoshop touch for android?

    Hello, I am very new to Ps Touch. Can someone explain how to use the glow function? Each time I do, i get the message "this filter needs transparent pixels." Not sure what to do, please help.

  • Referb Mac Mini!

    Apple recently lowered the price of the referb Mac Mini 1.25 to $399! I have a few questions if anybody knows. It comes with 256 ram and I will probably get a 1 gig stick anyway. Does anybody know were I can find a stick of 1 gb for around $100? My s