我试图将init$=new BehaviorSubject('initialvalue');
getData(init: boolean): Observable<any> {
const refreshInterval = 5000;
const interval = observableInterval(refreshInterval).pipe(startWith(0))
return interval.pipe(
withLatestFrom(init$),
flatMap(res=>this.apiSql.get<any>(this.getUrl(res[1]))),
map((data) => this.doWhateverWithData(data)),
);
}
所选项目绑定到init$.next('new value')
,我已经尝试过:
ComboBox
和:
TextBox
但是当我选择项目时,我进入<ComboBox x:Name="TitlesCombobox" IsEditable="True" IsReadOnly="True" Text="-- Subtitles --" >
<ComboBoxItem Content="sub title 1"/>
<ComboBoxItem Content="sub title 2"/>
<ComboBoxItem Content="sub title 3"/>
<ComboBoxItem Content="sub title 4"/>
</ComboBox>
:<TextBox x:Name="freestyleSubtitleTxt" Text="{Binding ElementName=TitlesCombobox, Path=SelectedValue}" />
答案 0 :(得分:2)
绑定到SelectedItem.Content
:
<TextBox x:Name="freestyleSubtitleTxt"
Text="{Binding ElementName=TitlesCombobox, Path=SelectedItem.Content}" />
或将ComboBoxItems
替换为strings
并绑定到SelectedItem
:
<ComboBox x:Name="TitlesCombobox" IsEditable="True" IsReadOnly="True" Text="-- Subtitles --"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String>sub title 1</s:String>
<s:String>sub title 2</s:String>
<s:String>sub title 3</s:String>
<s:String>sub title 4</s:String>
</ComboBox>
<TextBox x:Name="freestyleSubtitleTxt" Text="{Binding ElementName=TitlesCombobox, Path=SelectedItem}" />
答案 1 :(得分:1)
要仅绑定到ComboBoxItem
的值,请使用属性SelectedValuePath
。
您的ComboBox
应该如下所示:
<ComboBox x:Name="TitlesCombobox"
IsEditable="True"
IsReadOnly="True"
Text="-- Subtitles --"
SelectedValuePath="Content">
<ComboBoxItem Content="sub title 1"/>
<ComboBoxItem Content="sub title 2"/>
<ComboBoxItem Content="sub title 3"/>
<ComboBoxItem Content="sub title 4"/>
</ComboBox>
SelectedValuePath
属性指定用于确定SelectedValue
属性值的属性的路径。