Search code examples
autocompletecontrolssilverlight-toolkit

Silverlight: AutoCompleteBox and TextWrapping


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).


Solution

  • 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