3

Here's the problem: I have a data-bound list of items, basically a way for users to map a request to a response. The response is an xml-based file. I'm letting them queue these up, so I've used a combobox for responses. The responses will include the full path, so they get a bit long. I want the displayed text of the combobox to be right-justified so the user can see the file name. For my static controls, I just use ScrollToHorizontalOffset() when a file is loaded and I'm done. For this dynamic list, I'd like to do it in xaml.

The "somewhat ugly" solution would be to store all the ComboBox objects as they load... then I can call ScrollToHorizontalOffset() directly, but I'd really prefer to do it a cleaner way than that! EDIT: (Actually, this may not be reasonable. A quick look at trying to hack around this issue gets into some really awkward situations trying to map my datasource items to the controls)

I've tried HorizontalContentAlignment, that only impacts the "dropped-down" portion of the ComboBox.

I've also tried to hook other various loading events, but haven't found one that works.

EJA
  • 1,335
  • 1
  • 9
  • 11
  • The only way I see this could be done is having the content of each `ComboBoxItem` to be a trimmed string that shows only the last portion of the path using a converter (if the `ComboBox` is not a fixed width, you'd need to calculate how much text to leave). To help the user, you can set the ToolTip of the item and the combo to be bound to the full path. – XAMeLi May 13 '12 at 15:00
  • That's not a bad idea XAMeLi, but, I want to retain the editability of the fullpath. When the user clicks in the control, the whole item is highlighted and the cursor is right-justified. So the end result, on the click, is what I want. No user has complained at this point, so I've deferred this issue. I may pick it up again if I have time, but it's non-critical. – EJA May 14 '12 at 12:30

1 Answers1

1

Using an Item template you can decide what will be shown. You can set tooltip. You can then also use converters to add the dots.

<ComboBox x:Name="ConfigurationComboBox" VerticalContentAlignment="Center"  ToolTip="saved configuration" SelectionChanged="ConfigurationComboBox_SelectionChanged">
        <ComboBox.ItemTemplate>
           <DataTemplate >
               <StackPanel>
                  <TextBlock Text="{Binding}" ToolTip="{Binding Path}"></TextBlock>
               </StackPanel>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

To measure the text, see Measuring text in WPF.

Community
  • 1
  • 1
Joe Sonderegger
  • 784
  • 5
  • 15
  • This lead me in the right direction, thanks! I haven't used an empty "{Binding}" element like that. – EJA Jun 12 '12 at 16:17