这是我的具体情况。
Window资源代码:
...
<Window.Resources>
<ResourceDictionary>
<CollectionViewSource x:Key="AdditionalStringData" Source="{Binding ViewModelObservableCollection_String}"/>
<CollectionViewSource x:Key="AdditionalCustomObjectData" Source="{Binding ViewModelObservableCollection_CustomObject}"/>
<ResourceDictionary.MergedDictionaries>
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
...
我需要显示集合的部分:
...
<StackPanel>
<ItemsControl>
<ItemsControl.ItemsSource>
<CompositeCollection>
<TextBlock Text="{Binding ViewModelTextProperty}"/>
<Button Command="{Binding ViewModelRelayCommand}">Command</Button>
<CollectionContainer Collection="{Binding Source={StaticResource AdditionalStringData}}" />
<CollectionContainer Collection="{Binding Source={StaticResource AdditionalCustomObjectData}}" />
</CompositeCollection>
</ItemsControl.ItemsSource>
</ItemsControl>
</StackPanel>
...
ViewModel(假设它正确绑定)
...
private string ViewModelTextProperty { get; set; } = "Sample Text";
public RelayCommand ViewModelRelayCommand { ... }
private ObservableCollection<string> ViewModelObservableCollection_String { get; set; } = new ObservableCollection<string>();
private ObservableCollection<CustomObject> ViewModelObservableCollection_CustomObject { get; set; } = new ObservableCollection<CustomObject>();
...
Class CutomObject(可能不需要显示):
...
public class CustomObject
{
public string firstString;
public string secondString;
public CustomObject()
{
...
}
...
}
...
假设ObservableCollection
s具有适当的内容。
我的问题是:如何正确显示收藏品? 以下是标准:
ViewModelObservableCollection_String
个项目)是TextBlocks。其文本应为ViewModelObservableCollection_String
。ViewModelObservableCollection_CustomObject
项)是TextBoxes。其文本应为ViewModelObservableCollection_CustomObject
的单个项目的值(firstString
和secondString
的串联)。正如您所看到的,StackPanel的内容是多个Collection与不同DataTemplate
的合并。
如果事情不够清楚,请询问澄清。
答案 0 :(得分:1)
使用from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from time import sleep
import unittest
class Test_PythonOrg(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
sleep(4)
self.browser.close()
self.browser = None
def test_07_ListOfTodayDeals(self):
self.browser.get("http://www.amazon.com")
deals = self.browser.find_element_by_link_text("Today's Deals")
deals.click()
sleep(5)
self.browser.find_element_by_xpath("//span[@class='a-label a-checkbox-label' and contains(text(),'Books')]/preceding-sibling::input[1]").click()
self.browser.close()
if __name__ == "__main__":
unittest.main(verbosity=2)
内的DataTrigger
更改ItemTemplate
使用的ControlTemplate
,同时比较Control
。为此使用一个将返回类型的转换器。
或,
将Type
用作ContentControl
。
定义ItemTemplate
,其中包含DataTemplate
。 DataType
会自动为其ContentControl
选择适当的DataTemplate
。
第二种方法(推荐)
ContentTemplate