0
我有有一個DataTemplate這樣一個ListView:從多對象綁定到一個值,在XAML
<DataTemplate x:Key="FilterDataTemplate">
<StackPanel Orientation="Horizontal" Background="White" Height="50" HorizontalAlignment="Left">
<ComboBox x:Name="TermsItemComboBox" Width="160"
ItemsSource="{Binding ItemList}" Tag="{Binding}"
DisplayMemberPath="Key" SelectionChanged="AddTermsItem_SelectionChanged"
Background="#FFD1D1D1" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
<TextBox x:Name="TermsInputTxt1" Text="{Binding FilterText, Mode=TwoWay}"
BorderBrush="#FF727272" Background="#FFD1D1D1" HorizontalAlignment="Left"
Width="200" FontSize="16" VerticalAlignment="Center"
Visibility="{Binding IsTxtForm, Converter={StaticResource BooleanToVisibilityConverter}}"
Height="45"/>
<TextBox x:Name="TermsInputTxt2" Text="{Binding FilterText, Mode=TwoWay}"
BorderBrush="#FF727272" Background="#FFD1D1D1" HorizontalAlignment="Left"
Width="200" FontSize="16" VerticalAlignment="Center"
Visibility="{Binding IsTxtForm, Converter={StaticResource BooleanToVisibilityConverter}}"
Height="45"/>
<Button x:Name="TrashBtn" HorizontalAlignment="Left" VerticalAlignment="Stretch"
BorderBrush="#FF575757" Foreground="#FF494949" BorderThickness="2" Tapped="TrashBtn_Tapped"
Style="{StaticResource DiscardAppBarButtonStyle}" Height="45" Width="55"
RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<CompositeTransform ScaleX="-1" />
</Button.RenderTransform>
</Button>
</StackPanel>
這是有一個組合框和兩個文本框。默認情況下,組合框不顯示任何內容,只是一個空白項目,當用戶在TermInputTxt1或TermsInputTxt2中鍵入一些文本時,組合框將選擇第一個項目。
我嘗試使用轉換器將combobox的選定索引與這兩個文本框的長度綁定,但看起來像XAML不支持多重綁定。
有什麼建議嗎?謝謝!
我們可以從後面的代碼訪問TermsInputTxt1,TermsInputTxt2和組合框嗎?如果是的話,我認爲這種情況會更容易。 –
你可以,但是很難。你必須解析'VisualTree'。查找[WinRTXamlToolkit](http://winrtxamltoolkit.codeplex.com),因爲它有一些有用的擴展,比如'GetDescendends()'。 –
感謝您的建議,我試着做你建議的第一個解決方案,但是當用戶輸入時,我無法使文本框綁定,只有在文本框失去焦點時才起作用,我正在使用WIndows 8環境開發,沒有看到UpdateSourceTrigger或類似的東西,任何想法? –