如何从winui3 c++/winrt中的Combobox中获取用户选择项?
我想从Winui3 C ++/WinRT中的ComboBox中获取所选的用户项目。 XAML中有此代码:
<ComboBox x:Name="ComboTranslate" HorizontalAlignment="Center" Header="Translate to" SelectionChanged="ComboBox_SelectionChanged" SelectedIndex="0" Width="200" Margin="0,15,0,0">
<x:String>2</x:String>
<x:String>8</x:String>
<x:String>10</x:String>
<x:String>16</x:String>
</ComboBox>
在Winui3中的C#中,它实现如下:
private void ColorComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Add "using Windows.UI;" for Color and Colors.
string colorName = e.AddedItems[0].ToString();
Color color;
switch (colorName)
{
case "Yellow":
color = Colors.Yellow;
break;
case "Green":
color = Colors.Green;
break;
case "Blue":
color = Colors.Blue;
break;
case "Red":
color = Colors.Red;
break;
}
colorRectangle.Fill = new SolidColorBrush(color);
}
如何在C ++/WinRT上执行此操作?
I would like to get the selected user item from a ComboBox in WinUI3 C++/WinRT.
There is this code in XAML:
<ComboBox x:Name="ComboTranslate" HorizontalAlignment="Center" Header="Translate to" SelectionChanged="ComboBox_SelectionChanged" SelectedIndex="0" Width="200" Margin="0,15,0,0">
<x:String>2</x:String>
<x:String>8</x:String>
<x:String>10</x:String>
<x:String>16</x:String>
</ComboBox>
In C# in WinUI3 it is implemented as follows:
private void ColorComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Add "using Windows.UI;" for Color and Colors.
string colorName = e.AddedItems[0].ToString();
Color color;
switch (colorName)
{
case "Yellow":
color = Colors.Yellow;
break;
case "Green":
color = Colors.Green;
break;
case "Blue":
color = Colors.Blue;
break;
case "Red":
color = Colors.Red;
break;
}
colorRectangle.Fill = new SolidColorBrush(color);
}
How can you do this on C++/WinRT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我在PET项目的弹出窗口类上进行操作的方式,使用SelectedIndex()方法:
基本上,我在手动将事件处理程序连接到Combobox时,我并不使用发件人和事件的信息,上面的代码。
请不要判断我的C ++风格:我有点老派,而不是XAML的忠实拥护者!
Here's how I'm doing it on my pet project's PopUpButton class, using the SelectedIndex() method:
Basically, I'm not using the information of the sender and event as I manually connect the event handler to the ComboBox, the _hUIElement in the code above.
Please don't judge my C++ style: I'm a bit old school and not a big fan of XAML !