了解しました。私はC++開発者であり、現在WPFアプリに取り組んでいますが、これは難しい状況のようです。テキストボックスとボタンの両方が相互にバインドされているボタン、ラベルなどのセットを動的に生成しました。以前はC++コードでこれを行っていましたが、今はWPFアプリで行う必要があります。
XAML:
<ListBox x:Name="myViewChannelList" HorizontalAlignment="Stretch" Height="Auto" ItemsSource="{Binding VoltageCollection}" Margin="0" VerticalAlignment="Stretch" Width="Auto" >
<ListBox.Resources>
<convert:BooleanToVisibilityConverter x:Key="booltovisibility"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate >
<Grid Visibility="{Binding IsAvailable, Converter={StaticResource booltovisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding ChannelName}" Margin="50,20,0,0"></Label>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding VoltageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="25" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="170,20,0,0" />
<Button Grid.Column="1" Content="Set" Height="25" CommandParameter="{Binding VoltageText}" Command="{Binding VoltageCommand}" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20,20,0,0" ></Button>
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ViewModel:
private ICommand m_voltageCommand;
public ChannelList()
{
m_voltageCommand = new DelegateVoltageCommand(x => SetCommandExecute(x));
}
public void Initialize()
{
VoltageCollection = new ObservableCollection<VoltageModel> { new VoltageModel() { ChannelName = "", IsAvailable = false, VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
new VoltageModel() { ChannelName = "VDD__Main", IsAvailable = true, VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
new VoltageModel() { ChannelName = "VDD__IO__AUD", IsAvailable = true, VoltageText = String.Empty, VoltageCommand = m_voltageCommand },
new VoltageModel() { ChannelName = "VDD__CODEC__AUD", IsAvailable = true, VoltageText = String.Empty, VoltageCommand = m_voltageCommand }
};
}
ObservableCollection<VoltageModel> _voltages;
public ObservableCollection<VoltageModel> VoltageCollection
{
get
{
return _voltages;
}
set
{
_voltages = value;
OnPropertyChanged("VoltageCollection");
}
}
// Event when SET Button is clicked
public void SetCommandExecute(object voltageText)
{
string value = voltageText.ToString();
int val = Convert.ToInt32(value);
}
したがって、メソッドに示すように、ボタン+テキストボックス+ラベルを3回生成しInitialize()
ます。VoltageCommand = m_voltageCommand
これで、テキストボックスに入力されたテキストが表示され、ボルテージテキストが入力されSetCommandExecute(object voltageText)
た値を表示するメソッドが呼び出されます。
モデル:
string voltageText = string.Empty;
public string VoltageText
{
get
{
return voltageText;
}
set
{
voltageText = value;
OnPropertyChanged("VoltageText");
}
}
**C++ Code:**
// Since we have 3 channels, channel maintains count
if(button == m_setButton[channel])
{
unsigned cmd = 0x0300;
int numBytes = 0;
cmd |= (channel & 0xFF);
// Some code
ここでは、どのボタンがクリックされたかをユーザーに通知し、lの値を取ります。channe
つまり、2番目のボタンがクリックされた場合はchannel = 2
。
ここでは、C++1で記述されたコードを実装する必要があります。チャンネル、つまりどのボタンがクリックされたかを取得するにはどうすればよいですか。見てくださいcmd |= (channel & 0xFF);
、それはchannel
値を使用しました。アプリでそれを達成するにはどうすればよいですか?