views:

674

answers:

2

How to enable TextWrapping in the AutoCompleteBox control of the SilverlightToolkit (November 2009)? There is no property to set the wrapping mode. So is there any workaround?

Sven

Here are more infos about my current problem: To me the AutoCompleteBox consists of a list which displays all possible values and a TextBox where I enter a search string and display a selected value. I want now, that the selected value in the TextBox wraps.

So here is my current XAML, which uses the AutoCompleteBox in a DataGrid:

<data:DataGrid x:Name="GrdComponents" 
               ItemsSource="{Binding Path=Components}" AutoGenerateColumns="false" 
               Margin="4" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"
               HorizontalScrollBarVisibility="Visible">
  <data:DataGrid.Columns>  
    <data:DataGridTemplateColumn Header="Component" Width="230">
      <data:DataGridTemplateColumn.CellEditingTemplate >
        <DataTemplate>
          <input:AutoCompleteBox Text="{Binding Component.DataSource, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
                                 Loaded="AcMaterials_Loaded" 
                                 x:Name="Component"  
                                 SelectionChanged="AcMaterial_SelectionChanged"
                                 IsEnabled="{Binding Component.IsReadOnly, Mode=OneWay, Converter={StaticResource ReadOnlyConverter}}" 
                                 BindingValidationError="TextBox_BindingValidationError"
                                 ToolTipService.ToolTip="{Binding Component.Description}" 
                                 IsTextCompletionEnabled="False" FilterMode="Contains" 
                                 MinimumPopulateDelay="1" MinimumPrefixLength="3"
                                 ValueMemberPath="Description">
            <input:AutoCompleteBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding DescriptionTypeNumber}"/>
              </DataTemplate>
            </input:AutoCompleteBox.ItemTemplate>
          </input:AutoCompleteBox>
        </DataTemplate>
      </data:DataGridTemplateColumn.CellEditingTemplate>
    </data:DataGridTemplateColumn>
  </data:DataGrid.Columns> 
</data:DataGrid>

The AutoCompleteBox uses different values for the list (DescriptionTypeNumer) and for the selected value (Description).

A: 

TextWrapping="Wrap"

in context:

<TextBlock Margin="5" Text="Enter a date:" TextWrapping="Wrap" />
            <input:AutoCompleteBox VerticalAlignment="Top" Margin="5" Width="170" Height="30" x:Name="myACB" 
                ItemsSource="{Binding}" 
                ValueMemberBinding="{Binding Path=ReleaseDate, Converter={StaticResource FormatConverter}, 
                ConverterParameter=\{0:d\}}" >
            <input:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=ReleaseDate, Converter={StaticResource FormatConverter}, 
                    ConverterParameter=\{0:d\}}" />
                </DataTemplate>
            </input:AutoCompleteBox.ItemTemplate>
        </input:AutoCompleteBox>

from:

http://msdn.microsoft.com/en-us/library/system.windows.controls.autocompletebox.valuememberbinding(VS.95).aspx

another example:

<controls:AutoCompleteBox x:Name="Autocomplete_Single" Populating="AutoCompleteBox_Populating" SearchMode="None" IsTextCompletionEnabled="True"  Height="30" Width="100" Margin="10,10,0,0" KeyUp="Autocomplete_Single_KeyUp">
            <controls:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="10,0,0,0">
                        <TextBlock FontWeight="Bold" Width="80" HorizontalAlignment="Center" FontSize="12" Text="{Binding Mode=OneWay, Path=Name}"/>
                        <TextBlock TextWrapping="Wrap" Width="80" Text="{Binding Mode=OneWay, Path=ValueKindID}" FontSize="12"/>
                    </StackPanel>
                </DataTemplate>
            </controls:AutoCompleteBox.ItemTemplate>
        </controls:AutoCompleteBox>
James Campbell
No, the answer did not helped me. I will edit my original post to make the question more clear.
Sven Sönnichsen
A: 

Finally, the following did the trick: Define a Style for the textbox...

<UserControl.Resources>
  <Style x:Key="myTBStyle" TargetType="TextBox">
    <Setter Property="TextWrapping" Value="Wrap" />
  </Style>
</UserControl.Resources>

and then assign the Style:

<input:AutoCompleteBox TextBoxStyle="{StaticResource myTBStyle}"/>

Sven

Sven Sönnichsen