L'arrêt de WPF zone de texte de la croissance avec du texte

Je suis en train de modifier ma commande simple, de sorte que la zone de texte ne pousse pas tant que l'utilisateur tape dans un texte long. J'ai pris un coup d'oeil à quelques solutions de posté ici à Stackoverflow qui suggèrent l'utilisation d'une Grille et d'une Frontière invisible et de liaison de la Largeur de la zone de texte à la ActualWidth de la Frontière, mais je n'arrive pas à le faire fonctionner dans mon installation.

Voici le code xaml de mon contrôle:

<StackPanel Margin="5,0">
<WrapPanel Margin="0,0,0,5">
  <TextBlock Foreground="White" Margin="0,0,2,0">TEXT</TextBlock>
  <TextBlock Foreground="#FF0099CC" FontWeight="Bold">MORE TEXT</TextBlock>
</WrapPanel>
<Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
        BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
  <StackPanel Orientation="Horizontal">
    <Image Source="..\Resources\zoom.png" Width="13"/>
    <TextBox Foreground="White" Background="Black" BorderBrush="Transparent">THIS IS SOME TEXT</TextBox>
  </StackPanel>
</Border>
</StackPanel>

Des idées? J'ai besoin du zoom.png paraître "à l'intérieur" de la zone de texte donc j'utilise une pile horizontale du panneau et il suffit de placer l'image et la zone de texte côte à côte, entouré par la même frontière.

Est-il un moyen pour moi d'arrêter ma zone de texte à partir de l'auto de croissance en tant que texte est tapé?

Grâce.

Mise à JOUR:

Ci-dessous est le code xaml je suis en train de tester avec.

<Window x:Class="Desktop.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:composite="http://www.codeplex.com/CompositeWPF"
    Title="MyShell" Height="50" Width="900"
    WindowStyle="None"
    ShowInTaskbar="False"        
    AllowsTransparency="True"
    Background="Transparent"
    ResizeMode="CanResizeWithGrip"
    WindowStartupLocation="CenterScreen">
  <Border BorderBrush="Black"
                BorderThickness="1.5"
                CornerRadius="5"
                Background="Gray">
    <ItemsControl composite:RegionManager.RegionName="MainRegion">
      <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel></WrapPanel>
        </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
    </ItemsControl>
  </Border>
</Window>


<UserControl x:Class="Desktop.SearchTextBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="50" Margin="0">
  <StackPanel Margin="5,0">
    <WrapPanel Margin="0,0,0,5">
      <TextBlock Foreground="White" Margin="0,0,2,0">TEXT</TextBlock>
      <TextBlock Foreground="#FF0099CC" FontWeight="Bold">MORE TEXT</TextBlock>
    </WrapPanel>
    <Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
        BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
        <Grid x:Name="grdTest">
          <Image HorizontalAlignment="Left" Source="..\Resources\zoom.png" Width="13"/>
          <TextBox Margin="16,0,0,0"  Foreground="White" Background="Black" BorderBrush="Transparent" Width="{Binding ElementName=grdTest, Path=ActualWidth}">THIS IS SOME TEXT</TextBox>
        </Grid>
    </Border>
  </StackPanel>
</UserControl>

Je viens ajouter mon contrôle de l'utilisateur de la Fenêtre MainRegion.

InformationsquelleAutor Flack | 2010-09-15