Silverlight:AutoCompleteBox和TextWrapping

时间:2010-03-11 15:40:24

标签: autocomplete controls silverlight-toolkit

如何在SilverlightToolkit的AutoCompleteBox控件中启用TextWrapping(2009年11月)? 没有属性可以设置包装模式。那么有什么解决方法吗?

斯文

以下是关于我当前问题的更多信息:对我来说,AutoCompleteBox包含一个显示所有可能值的列表和一个TextBox,我输入一个搜索字符串并显示一个选定的值。我现在想要,TextBox中的选定值包装。

所以这是我当前的XAML,它使用DataGrid中的AutoCompleteBox:

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

AutoCompleteBox对列表(DescriptionTypeNumer)和所选值(描述)使用不同的值。

2 个答案:

答案 0 :(得分:2)

最后,以下功能:为文本框定义样式......

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

然后指定样式:

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

斯文

答案 1 :(得分:0)

TextWrapping = “包装”

在上下文中:

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

从:

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

另一个例子:

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