开发者

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>
        <开发者_如何学Go;/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).


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜