OT: WPF combobox

OT: WPF combobox

Old forum URL: forums.lhotka.net/forums/t/4120.aspx


ajj3085 posted on Friday, January 04, 2008

Hi,

I have a WPF control with a combobox.  The ItemTemplate is defined like this:

<ComboBox.ItemTemplate>

    <DataTemplate>

        <Grid HorizontalAlignment="Left">

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="140" />

                <ColumnDefinition Width="140" />

            </Grid.ColumnDefinitions>

            <TextBox Grid.Column="0" Height="Auto" IsReadOnly="{Binding Converter={StaticResource NegationFormatter}, Path=IsNew}" Text="{Binding Path=Number}" Name="Number" Width="140" />

            <TextBox Grid.Column="1" Height="Auto" IsReadOnly="{Binding Converter={StaticResource NegationFormatter}, Path=IsNew}" Text="{Binding Path=Extension}" Name="Extension" Width="140" />

        </Grid>

       </DataTemplate>

</ComboBox.ItemTemplate>


What I'd like to do is have a Click on the textboxes select the item to which they belong, instead of moving the focus to the textbox.  I'm sure there's something simple I'm missing, but I can't figure out how to do this..

Thanks
Andy

chrislw replied on Friday, January 11, 2008

Sounds like you want a label instead of a textbox.  Can you explain the problem in more detail?

ajj3085 replied on Friday, January 11, 2008

Well, the problem I want to solve is that I have a list of Phone numbers.  The user can select an existing one (but not edit) or can enter a new one and select it.  If you databind the combobox items, is there a way to specify a different template based on some arbitrary value?  I don't have a problem with Label or TextBlock, but I do need the last time in the combobox's items to be TextBoxes.

chrislw replied on Friday, January 11, 2008

I'm looking into the switching template idea.  I like that idea. 

As for the textbox focus causing the item to be selected, check out this link:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2616125&SiteID=1

Meanwhile, I'll let you know if I find out the template idea.

ajj3085 replied on Friday, January 11, 2008

Awesome, thanks.

Copyright (c) Marimer LLC