about ui update

2 posts, 0 answers
  1. Li
    Li avatar
    1 posts
    Member since:
    Mar 2012

    Posted 13 Sep 2013 Link to this post

    i have used a RadTileView, 
    <UserControl
                 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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                 x:Class="DemoShow.usercontrol.UserControl1" 
                 mc:Ignorable="d" >
        <UserControl.Resources>

            <Style x:Key="TextBoxThumb" TargetType="TextBox">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="true">
                        <Setter Property="BorderThickness" Value="1,1,1,1" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="BorderThickness" Value="0,0,0,0"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <DataTemplate x:Key="headerTemplate">
                <TextBlock Text="{Binding Number}" />
            </DataTemplate>
            <DataTemplate x:Key="contentTemplate">
                <Grid Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBox Grid.Row="0" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Text="{Binding Name,Mode=TwoWay}" />
                    <TextBox Grid.Row="1" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Birthday,Mode=TwoWay}" />
                    <TextBox Grid.Row="2" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding age,Mode=TwoWay}" />
                    <TextBox Grid.Row="3" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Sex,Mode=TwoWay}" />
                    <TextBox Grid.Row="4" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding CheckType,Mode=TwoWay}" />
                    <TextBox Grid.Row="5" Style="{StaticResource TextBoxThumb}" IsEnabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Time,Mode=TwoWay}" />
                    <Button Grid.Row="5"  Content="123" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <i:InvokeCommandAction  Command="{Binding DataContext.LoginCommand,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}, AncestorLevel=1}}"
                                    CommandParameter="{Binding Name}"
                                    />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>

                </Grid>
            </DataTemplate>
        </UserControl.Resources>
        <Grid>
            <telerik:RadTileView  
                             IsAutoScrollingEnabled="True"
                        IsDockingEnabled="True"
                        IsVirtualizing="True"
                             ColumnsCount="2"
                             RowHeight="200"
                             ColumnWidth="300"
                             MinimizedColumnWidth="300"
                             MinimizedRowHeight="200"
                             MinimizedItemsPosition="Bottom"
                             ContentTemplate="{StaticResource contentTemplate}"
                        ItemsSource="{Binding Path=Items,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        ItemTemplate="{StaticResource headerTemplate}"
                        PreservePositionWhenMaximized="False"
                        TileStateChangeTrigger="SingleClick">
            </telerik:RadTileView>

        </Grid>

    </UserControl>

    i change the BindingList<People>

      public class MainViewModel : ViewModelBase
        {
            private BindingList<People> items;
            private BindingList<People> itemstem;

            public ICommand LoginCommand
            {
                get
                {
                    return new RelayCommand<object>(
                        (parameter) =>
                        {
                            ChangeInputEnable(parameter);
                        }
                        );
                }
            }

    ui not update      public class People
        {
            public string Name { get; set; }
            public string Birthday { get; set;}
            public string age { get; set; }
            public string Sex { get; set; }
            public string CheckType { get; set; }
            public string Time { get; set; }
            public string Number { get; set; }
            public bool ShowFlag { get; set; }
        }

            private void ChangeInputEnable(object parameter)
            {

                //string str = parameter.ToString();
                //var obj = items.FirstOrDefault(x => x.Name == str);
                //int n = items.IndexOf(obj);
                //MessageBox.Show(items[n].ShowFlag.ToString());
                //if (obj != null)
                //{
                //    if (obj.ShowFlag) obj.ShowFlag = false;
                //    else obj.ShowFlag = true;

                //    RaisePropertyChanged("ShowFlag");
                //    RaisePropertyChanged("Items");
                //    MessageBox.Show(items[n].ShowFlag.ToString());
                //    MessageBox.Show(str);
                //}


                string str = parameter.ToString();
                var obj = items.FirstOrDefault(x => x.Name == str);
                int n = items.IndexOf(obj);
                if (obj != null)
                {
                    if (obj.ShowFlag) obj.ShowFlag = false;
                    else obj.ShowFlag = true;
                    obj.Name += "tttt";
                    items.ListChanged += (o, e) => RaisePropertyChanged(("Items"));

                    itemstem = items;
                    items = null;
                    items = itemstem;
                    RaisePropertyChanged("Name");
                    
                    RaisePropertyChanged("Items");
                }


                //items.Add(new People()
                //{
                //    Birthday = "1985-08-08",
                //    age = "38",
                //    Sex = "Male",
                //    CheckType = "PET-CT",
                //    Time = "10:30",
                //    Name = "tttt",
                //    Number = "10"
                //});

                //RaisePropertyChanged("Items");


            }

            public MainViewModel()
            {
                List<People> itemsSource = new List<People>();
                for (int i = 0; i < 5; i++)
                {
                    itemsSource.Add(new People()
                    {
                        Birthday = "1985-08-08",
                        age = "38",
                        Sex = "Male",
                        CheckType = "PET-CT",
                        Time = "10:30",
                        Name = this.names[i % 12],
                        Number = i.ToString(),
                        ShowFlag =true
                    });
                }

                this.items = new BindingList<People>(itemsSource);
            }


            public BindingList<People> Items
            {
                get
                {
                    return this.items;
                }
                set
                {
                    this.items =value;
                    RaisePropertyChanged("Items");
                }
            }

            private List<string> names = new List<string>
            {
                "Andrew Fuller",
                "Martin Sommer",
                "Anne Dogsworth",
                "Steven Buchanan",
                "Janet Leverling",
                "Michael Suyama",
                "Margaret Peacock",
                "Robert King",
                "John Steel",
                "Laura Gallahan",
                "Nancy Davolio",
                "Ann Devon"
            };
        }

    can you help me ?

  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 17 Sep 2013 Link to this post

    Hello,

    Thank you for contacting us on that matter. I can see from the provided snippet that the properties that yo have defined does not invoke the PropertyChanged event.

    In order to make sure that each property will notify the UI that it has been changed you can define all of them like this:

    private string _name;
    public string Name
    {
        get { return this._name; }
        set
        {
            if (this._name != value)
            {
                this._name = value;
                this.OnPropertyChanged("Name");
            }
        }
    }
    Basically, if you define all the properties in your custom People class your UI will be updated right after you change some property. Please note that you can derive your People class from Telerik's ViewModelBase which implements the INotifyPropertyChanged interface. Hence, you will not need to invoke the PropertyChanged event manually.

    I hope that this information is helpful.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top