Как реализовать управление Переключателем XAML с источником ObservableCollection?

Посмотрите на исходный код JRE, и Вы будете, вероятно, видеть различие. Или ни один. На самом деле Strinv.valueOf (международное нечто) реализован следующим образом:

public static String valueOf(int i) {
    return Integer.toString(i, 10);
}

и Integer.toString (международное нечто, международное основание)

public static String toString(int i, int radix) {
   ...
   if (radix == 10) {
   return toString(i);
   }
   ...
}

, Что означает при использовании основания 10 лучше вызов Integer.toString (международное нечто) непосредственно. Поскольку другие случаи используют Integer.toString (международное нечто, международное основание).

concat решение сначала преобразовывает международное значение в Строку и позже конкатенирует с пустой строкой. Это, очевидно - самый дорогой случай.

6
задан Edward Tanguay 15 September 2009 в 08:58
поделиться

2 ответа

Use ItemsControl and DataTemplate:

<ItemsControl ItemsSource="{Binding CollectionControlValues}">
  <DataTemplate>
    <RadioButton Content="{Binding Value} IsChecked={Binding SomeProperty}" GroupName="name"/>
  </DataTemplate>
</ItemsControl>
5
ответ дан 17 December 2019 в 02:31
поделиться

код в файле window1.xaml

<Window x="RadioButton.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local ="clr-namespace:RadioButton"
    Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<StackPanel>
    <StackPanel.Resources>
        <ObjectDataProvider x:Key="RadioOptions" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:RadioOption" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <Style x:Key="RadioButtonList" TargetType="{x:Type ListBox}">

            <Setter Property="BorderBrush" Value="{x:Null}" />

            <Setter Property="BorderThickness" Value="0" />

            <Setter Property="ItemContainerStyle">

                <Setter.Value>

                    <Style TargetType="{x:Type ListBoxItem}" >

                        <Setter Property="Margin" Value="2" />

                        <Setter Property="Template">

                            <Setter.Value>

                                <ControlTemplate TargetType="{x:Type ListBoxItem}">

                                    <Border Background="Transparent">

                                        <RadioButton Focusable="False"

                    IsHitTestVisible="False"

                    IsChecked="{TemplateBinding IsSelected}">

                                            <ContentPresenter />

                                        </RadioButton>

                                    </Border>

                                </ControlTemplate>

                            </Setter.Value>

                        </Setter>

                    </Style>

                </Setter.Value>

            </Setter>

        </Style>
    </StackPanel.Resources>
    <ListBox Margin="37,20,28,58" Name="listBox1" Style="{StaticResource RadioButtonList}" ItemsSource="{Binding Source={StaticResource RadioOptions}}"  />
</StackPanel>

эта строка

<ListBox` Margin="37,20,28,58" Name="listBox1" Style="{StaticResource RadioButtonList}" 
 ItemsSource="{Binding Source={StaticResource RadioOptions}}" 

использует свойство itemsource

Код C #

namespace RadioButton
{
   public enum RadioOption
   {
    option1,
    option2,
    option3,
    option4
   }

public partial class Window1 : Window

{
    public Window1()

    {

        InitializeComponent();

    }

}

}

я думаю, это поможет вам ..

1
ответ дан 17 December 2019 в 02:31
поделиться
Другие вопросы по тегам:

Похожие вопросы: