好吧,我必须在这里冻结大脑......
我有一个包含6个项目的ComboBox,我正在尝试将所选项目绑定到整数值.它不起作用,我怀疑它是因为ComboBoxItem是字符串.我不想在代码后面填写一个列表来填充这个小盒子,所以在xaml中是否有一种方法可以告诉组合框架它们是否保持整数?喜欢的东西<x:Int>2</x:Int>可能?
XAML:
<ComboBox SelectedItem="{Binding SavedPrintTicket.PagesPerSheet}">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud) 我已经在我的视图模型中将ComboBox的SelectedItemChangeEvent连接到ICommand.一切似乎工作正常,但我不知道如何获得ComboxBox的SelectedItem.我想我需要使用EventToCommand的CommandParameter - 我将它绑定到我的ViewModel中具有ComboBox的selectedItem的东西吗?我试过这个:
<ComboBox
Width="422"
Height="24"
DisplayMemberPath="Name"
ItemsSource="{Binding CategoryTypes}"
SelectedItem="{Binding SelectedCategory}"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<MvvmLight:EventToCommand
Command="{Binding SelectCategoryCommand,Mode=TwoWay}"
CommandParameter="{Binding SelectedCategory, Mode=TwoWay}"
MustToggleIsEnabledValue="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中:
public ICommand SelectCategoryCommand
{
get
{
return new SelectCategoryCommand(this);
}
}
public CategoryType SelectedCategory
{
get; set;
}
Run Code Online (Sandbox Code Playgroud)
和ICommand
public class SelectCategoryCommand : ICommand
{
private RowViewModel _rowViewModel;
public SelectCategoryCommand(RowViewModel rowViewModel)
{
_rowViewModel = rowViewModel;
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{ …Run Code Online (Sandbox Code Playgroud) 我创建了一个ListBox有DataTemplateas的Itemtemplate.但是,是否有一种简单的方法来访问生成UIElement而不是代码SelectedItem隐藏?
当我访问时SelectedItem,我只是从我的ItemsSource集合中获取所选对象
.有没有办法访问UIElement(即从DataTemplate绑定对象一起生成的元素)?
ListBox的行为是自动选择第一个项目,我该如何避免?
注意:我更喜欢用纯xaml做这个,如果你有任何代码隐藏的想法,那么请不要打扰自己.
嗨,我有两个问题.
好吧,我的C#WPF ListView控件存在更多问题.这里充满了荣耀:
<Window x:Class="ebook.SearchResults" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="ISBNListView" Height="503" Width="1004">
<Grid>
<ListView Name="listView1" Margin"22,30,33,28" MouseDoubleClick="getSelectedItem" >
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="ISBN" Width="150" DisplayMemberBinding="{Binding ISBN}"/>
<GridViewColumn Header="Title" Width="350" DisplayMemberBinding="{Binding Title}"/>
<GridViewColumn Header="Author" Width="350" DisplayMemberBinding="{Binding Author}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我用以下内容填充listView:
XDocument xdoc = XDocument.Load(GlobalVars.docPath + "\\tempSearchResults.xml");
var items = from item in xdoc.Descendants("Book")
select new
{
ISBN = item.Element("ISBN").Value,
Title = item.Element("Title").Value,
AuthTexts = item.Element("Author").Value
};
foreach (var item in items)
{
listView1.Items.Add(new { ISBN = item.ISBN, Title = item.Title, Author …Run Code Online (Sandbox Code Playgroud) 我有一个Listview,其中有一个复选框作为列之一.如果我点击实际复选框的任何位置,ListView的SelectedItem将按预期设置为当前选定的行.另一方面,如果我单击复选框(不先单击该行),则SelectedItem为null或先前单击的行.
谁能帮我吗....
干杯
<ListView Width="auto" SelectionMode="Single" x:Name="listBox" ItemsSource="{Binding MyData}" SelectedItem="{Binding Path=SelectedMyData}">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ContentPresenter Style="{StaticResource DateTimeContent}" Content="{Binding MyDate}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Is Correct" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsThreeState="False"
Checked="OnChkChecked"
Unchecked="OnChkChecked"
IsChecked="{Binding IsCorrect}"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsThreeState="False"
Checked="OnChkChecked"
Unchecked="OnChkChecked"
IsChecked="{Binding IsCorrect}"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud) 我目前正面临一个问题.如何从asp.net复选框列表中获取最新选定的值?
从循环到复选框列表的项目,我可以获得最高选择的索引及其值,但不希望用户从低到高的索引顺序选择复选框.那么,如何处理呢?
是否有任何事件捕获系统可以帮助我识别生成事件的确切列表项?
List<Customer> _customers = getCustomers().ToList();
BindingSource bsCustomers = new BindingSource();
bsCustomers.DataSource = _customers;
comboBox.DataSource = bsCustomers.DataSource;
comboBox.DisplayMember = "name";
comboBox.ValueMember = "id";
Run Code Online (Sandbox Code Playgroud)
现在,如何将组合框的项目设置为列表中第一个以外的其他项目?尝试过comboBox.SelectedItem = someCustomer; ...还有很多其他东西,但到目前为止没有运气......
如何使用Selenium WebDriver和Python获取所选选项:
有人有解决方案getFirstSelectedOption吗?
我用它来获取select元素:
try:
FCSelect = driver.find_element_by_id('FCenter')
self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Select found"
except NoSuchElementException:
self.TestEventLog = self.TestEventLog + "<br>Error: Select FCenter element not found"
Run Code Online (Sandbox Code Playgroud)
是否存在类似于或类似于'getFirstSelectedOption'的内容,如下所示:
try:
FCenterSelectedOption = FCenterSelect.getFirstSelectedOption()
self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Selected (First) found"
except NoSuchElementException:
self.TestEventLog = self.TestEventLog + "<br>Error: Selected Option element not found"
Run Code Online (Sandbox Code Playgroud)
然后我想用以下内容验证内容getText:
try:
FCenterSelectedOptionText = FCenterSelectedOption.getText()
self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: FCenter Selected Option Text …Run Code Online (Sandbox Code Playgroud) selecteditem ×10
wpf ×6
c# ×3
combobox ×2
listbox ×2
listview ×2
asp.net ×1
binding ×1
checkbox ×1
checkboxlist ×1
datasource ×1
datatemplate ×1
mvvm-light ×1
python ×1
selected ×1
selenium ×1
silverlight ×1
tabcontrol ×1
uielement ×1