Beispiel #1
0
        private IElement CreateListBoxItem(GameViewModel content)
        {
            var textBlock = new TextBlock(FontManager[Fonts.Normal])
            {
                Text       = content.GameName,
                Foreground = new SolidColorBrush(Colors.White),
                Margin     = new Thickness(0, 10, 0, 10),
            };

            var border = new Border()
            {
                Child = textBlock
            };
            var listBoxItem = new ListBoxItem()
            {
                Content = border
            };

            textBlock.Bind(TextBlock.ForegroundProperty,
                           listBoxItem.GetObservable <bool, ListBoxItem>(ListBoxItem.IsSelectedProperty)
                           .Select(
                               isSelected =>
                               (Brush)
                               (isSelected ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.White))));
            border.Bind(Border.BackgroundProperty,
                        listBoxItem.GetObservable <bool, ListBoxItem>(ListBoxItem.IsSelectedProperty)
                        .Select(
                            isSelected =>
                            (Brush)
                            (isSelected ? new SolidColorBrush(Colors.Gray) : new SolidColorBrush(Colors.Black))));

            content.PropertyChanged += delegate { listBoxItem.IsSelected = content.IsSelected; };

            listBoxItem.Bind(ListBoxItem.IsSelectedProperty, BindingFactory.CreateTwoWay(content, c => c.IsSelected));
            return(listBoxItem);
        }