Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present a ComboBox as TextBlock in WPF/Silverlight

I want to display a ComboBox as TextBox (without border, background, toggle button, ect.) - only current selected item text. I do like this, but I can not understand how to link TextBlock, so that it displays the currently selected item in the ComboBox.

<ComboBox ItemsSource="{Binding Path=...}" SelectedValue="{Binding Path=...}" DisplayMemberPath="Name" SelectedValuePath="Id">
    <ComboBox.Template>
        <ControlTemplate>
            <TextBlock Text="{Binding ?}"></TextBlock>
        </ControlTemplate>
    </ComboBox.Template>
</ComboBox>
like image 348
Roman Kopaev Avatar asked Dec 24 '12 17:12

Roman Kopaev


1 Answers

<ComboBox ItemsSource="{Binding Path=...}" SelectedValue="{Binding Path=...}" DisplayMemberPath="Name" SelectedValuePath="Id">
<ComboBox.Template>
    <ControlTemplate>
        <TextBlock Text="{Binding SelectedItem.MyText,RelativeSource={RelativeSource Mode=TemplatedParent}}"></TextBlock>
    </ControlTemplate>
</ComboBox.Template>

like image 71
user1064519 Avatar answered Sep 28 '22 10:09

user1064519