2011-11-09 22 views

回答

5

从XAML:

<TextBox Name="myTextBox" TextChanged="OnTextBoxTextChanged" Width="200"> 
    <TextBox.Background> 
    <ImageBrush ImageSource="TextBoxBackground.gif" AlignmentX="Left" Stretch="None" /> 
    </TextBox.Background> 
</TextBox> 

从C#

// Create an ImageBrush. 
ImageBrush textImageBrush = new ImageBrush(); 
textImageBrush.ImageSource = new BitmapImage(new Uri(@"TextBoxBackground.gif", UriKind.Relative)); 
textImageBrush.AlignmentX = AlignmentX.Left; 
textImageBrush.Stretch = Stretch.None; 
// Use the brush to paint the button's background. 
myTextBox.Background = textImageBrush; 

Source

+0

是否也可以抵消文本,以便它不覆盖图标? – SharpShade

相关问题