Beispiel #1
1
        private void UpdateContent()
        {
            if (panel == null)
                return;

            panel.Children.Clear();
            
            if (Value == null)
                return;
            
            var enumValues = Enum.GetValues(Value.GetType()).FilterOnBrowsableAttribute();
            var converter = new EnumToBooleanConverter { EnumType = Value.GetType() };
            var relativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(RadioButtonList), 1);
            var descriptionConverter = new EnumDescriptionConverter();

            foreach (var itemValue in enumValues )
            {
                var rb = new RadioButton { Content = descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture) };
                // rb.IsChecked = Value.Equals(itemValue);

                var isCheckedBinding = new Binding("Value")
                                           {
                                               Converter = converter,
                                               ConverterParameter = itemValue,
                                               Mode = BindingMode.TwoWay,
                                               RelativeSource = relativeSource
                                           };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                var itemMarginBinding = new Binding("ItemMargin") { RelativeSource = relativeSource };
                rb.SetBinding(MarginProperty, itemMarginBinding);

                panel.Children.Add(rb);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the content.
        /// </summary>
        private void UpdateContent()
        {
            if (this.panel == null)
            {
                return;
            }

            this.panel.Children.Clear();

            var enumType = this.EnumType;

            if (enumType != null)
            {
                var ult = Nullable.GetUnderlyingType(enumType);
                if (ult != null)
                {
                    enumType = ult;
                }
            }

            if (this.Value != null)
            {
                enumType = this.Value.GetType();
            }

            if (enumType == null || !typeof(Enum).IsAssignableFrom(enumType))
            {
                return;
            }

            var enumValues = Enum.GetValues(enumType).FilterOnBrowsableAttribute();
            var converter  = new EnumToBooleanConverter {
                EnumType = enumType
            };
            var descriptionConverter = new EnumDescriptionConverter();

            foreach (var itemValue in enumValues)
            {
                var rb = new RadioButton
                {
                    Content =
                        descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture),
                    Padding = this.ItemPadding
                };

                var isCheckedBinding = new Binding("Value")
                {
                    Converter = converter, ConverterParameter = itemValue, Source = this, Mode = BindingMode.TwoWay
                };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                var itemMarginBinding = new Binding("ItemMargin")
                {
                    Source = this
                };
                rb.SetBinding(MarginProperty, itemMarginBinding);

                this.panel.Children.Add(rb);
            }
        }
Beispiel #3
0
        private void UpdateContent()
        {
            if (panel == null)
            {
                return;
            }

            panel.Children.Clear();

            if (Value == null)
            {
                return;
            }

            var enumValues = Enum.GetValues(Value.GetType()).FilterOnBrowsableAttribute();
            var converter  = new EnumToBooleanConverter {
                EnumType = Value.GetType()
            };
            var relativeSource       = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(RadioButtonList), 1);
            var descriptionConverter = new EnumDescriptionConverter();

            foreach (var itemValue in enumValues)
            {
                var rb = new RadioButton {
                    Content = descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture)
                };
                // rb.IsChecked = Value.Equals(itemValue);

                var isCheckedBinding = new Binding("Value")
                {
                    Converter          = converter,
                    ConverterParameter = itemValue,
                    Mode           = BindingMode.TwoWay,
                    RelativeSource = relativeSource
                };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                var itemMarginBinding = new Binding("ItemMargin")
                {
                    RelativeSource = relativeSource
                };
                rb.SetBinding(MarginProperty, itemMarginBinding);

                panel.Children.Add(rb);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Updates the content.
        /// </summary>
        private void UpdateContent()
        {
            if (this.panel == null)
            {
                return;
            }

            this.panel.Children.Clear();

            var enumType = this.EnumType;
            if (enumType != null)
            {
                var ult = Nullable.GetUnderlyingType(enumType);
                if (ult != null)
                {
                    enumType = ult;
                }
            }

            if (this.Value != null)
            {
                enumType = this.Value.GetType();
            }

            if (enumType == null || !typeof(Enum).IsAssignableFrom(enumType))
            {
                return;
            }

            var enumValues = Enum.GetValues(enumType).FilterOnBrowsableAttribute();
            var converter = new EnumToBooleanConverter { EnumType = enumType };
            var descriptionConverter = new EnumDescriptionConverter();

            foreach (var itemValue in enumValues)
            {
                var rb = new RadioButton
                    {
                        Content =
                            descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture),
                        Padding = this.ItemPadding
                    };

                var isCheckedBinding = new Binding("Value")
                    {
                       Converter = converter, ConverterParameter = itemValue, Source = this, Mode = BindingMode.TwoWay
                    };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                var itemMarginBinding = new Binding("ItemMargin") { Source = this };
                rb.SetBinding(MarginProperty, itemMarginBinding);

                this.panel.Children.Add(rb);
            }
        }