라디오 버튼 클릭을 기반으로하는 라벨의 동적 생성 작업을하고 있습니다. 음, 나는 그것을 성공적으로 수행했지만 단추를 클릭 할 때마다 레이블을 생성하지만 이전 상태를 지우지 않습니다.라디오 버튼에서 이전에 표시된 라벨을 지우지 못했습니다. wpf에서 클릭하십시오.
XAML :
<Grid Grid.Row="0">
<ItemsControl ItemsSource="{Binding Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" >
<RadioButton Content="{Binding RadioBase}" Margin="0,10,0,0" IsChecked="{Binding BaseCheck}" GroupName="SlotGroup" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Grid Grid.Row="1">
<ItemsControl ItemsSource="{Binding Children}" Grid.Column="0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<ItemsControl Visibility="{Binding IsRegisterItemsVisible, Converter={StaticResource BoolToVisibilityConv}}" ItemsSource="{Binding RegisterLabels}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="50,20,0,0">
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
FPGARadioWidgetViewModel 클래스 :이 클래스의 DataContext를 여기에 설정되어
public ObservableCollection<FPGAViewModel> Children { get; set; }
public FPGARadioWidgetViewModel()
{
Children = new ObservableCollection<FPGAViewModel>();
Children.Add(new FPGAViewModel() { RadioBase = "Base 0x0", ID = 0 });
Children.Add(new FPGAViewModel() { RadioBase = "Base 0x40", ID = 1 });
Children.Add(new FPGAViewModel() { RadioBase = "Base 0x80", ID = 2 });
Children.Add(new FPGAViewModel() { RadioBase = "Base 0xc0", ID = 3 });
}
FPGAViewModel 등급 :
private bool sBaseCheck;
public bool BaseCheck
{
get { return this.sBaseCheck; }
set
{
this.sBaseCheck = value;
Generatelabels(this, ID);
this.OnPropertyChanged("BaseCheck");
}
}
private static void Generatelabels(FPGAViewModel currentItem, int index)
{
int m_baseRegister = 0;
if (index == 0)
{
for (int i = 0; i < 0x40/8; i++)
{
int reg = (i * 8) + m_baseRegister;
currentItem.RegisterLabels[i] = "Reg 0x" + reg.ToString("X");
currentItem.IsRegisterItemsVisible = true;
}
}
else if (index == 1)
{
m_baseRegister = 0x40 * index;
for (int i = 0; i < 0x40/8; i++)
{
int reg = (i * 8) + m_baseRegister;
currentItem.RegisterLabels[i] = "Reg 0x" + reg.ToString("X");
currentItem.IsRegisterItemsVisible = true;
}
}
// Similarly for Index 2 and Index = 3
}
private string[] registerLabels = new string[8];
public string[] RegisterLabels { get { return registerLabels; } }
private bool isRegisterItemsVisible = false;
public bool IsRegisterItemsVisible
{
get { return isRegisterItemsVisible; }
set
{
isRegisterItemsVisible = value;
OnPropertyChanged("IsRegisterItemsVisible");
OnPropertyChanged("RegisterLabels");
}
}
01 여기에 코드입니다
라디오 버튼 클릭시 8 개의 라벨이 표시됩니다. 두 번째 라디오 버튼을 클릭하면 다른 8을 표시하고 이전 8을 지우지 않습니다. 기본적으로 한 번에 선택한 라디오 버튼의 8 개의 라벨 만 표시되어야합니다. 어떻게 달성 될 수 있습니까?
감사합니다. 샘플 코드로 정교하게 만들 수 있습니까? 나는 그것이 실제로 도움이 될 것이라고 생각합니다. –
편집보기 ....... – GazTheDestroyer
@SteveWilson 이것은 샘플 코드를 요청한 것을 볼 수있는 세 번째 시간입니다. 나는 이미 당신에게 이것을 달성하기 위해 당신이 당신의 사물들 사이에 필요로했던 고등학 적 관계를 형성하는 데 필요한 사고 방식을 설명했다. 게으르지 말고 다른 사람에게 일하는 것을 중단하십시오. =) –