Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Windows Phone中创建带下划线的输入文本字段?_C#_Silverlight_Windows Phone 7_Xaml_Textbox - Fatal编程技术网

C# 如何在Windows Phone中创建带下划线的输入文本字段?

C# 如何在Windows Phone中创建带下划线的输入文本字段?,c#,silverlight,windows-phone-7,xaml,textbox,C#,Silverlight,Windows Phone 7,Xaml,Textbox,制作文本框(看起来像带下划线的输入文本字段)最简单和正确的方法是什么?您可以在信息中心的屏幕顶部和诺基亚交通工具中看到我所说的示例 我应该使用什么技术来实现它 覆盖文本框的模板以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness=“0 0 0 1”覆盖文本框的模板以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness的边框=“0 0 1”要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始 <Border

制作文本框(看起来像带下划线的输入文本字段)最简单和正确的方法是什么?您可以在信息中心的屏幕顶部和诺基亚交通工具中看到我所说的示例

我应该使用什么技术来实现它


覆盖文本框的
模板
以无背景或边框,然后在标签和文本框周围放置一个带有
BorderThickness=“0 0 0 1”
覆盖文本框的
模板
以无背景或边框,然后在标签和文本框周围放置一个带有
BorderThickness的边框=“0 0 1”

要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始

    <Border BorderBrush="White" BorderThickness="0,0,0,2">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="To:" Style="{StaticResource PhoneTextTitle2Style}" Margin="12,5" VerticalAlignment="Bottom"/>
            <TextBox Grid.Column="1" Background="Transparent" BorderThickness="0" Foreground="{StaticResource PhoneSubtleBrush}" Text="This is a test"
                     VerticalAlignment="Bottom" />
        </Grid>
    </Border>

要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始

    <Border BorderBrush="White" BorderThickness="0,0,0,2">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="To:" Style="{StaticResource PhoneTextTitle2Style}" Margin="12,5" VerticalAlignment="Bottom"/>
            <TextBox Grid.Column="1" Background="Transparent" BorderThickness="0" Foreground="{StaticResource PhoneSubtleBrush}" Text="This is a test"
                     VerticalAlignment="Bottom" />
        </Grid>
    </Border>

这可能是一种简单的方法:

  • 首先,将文本框和边框的默认背景设置为透明

  • 然后,您可以使用Shawn Kendrot的答案获得下划线(因为您需要在文本框中添加标签)

  • 最后,要使聚焦文本框背景透明,必须遵循以下步骤

或者您可以创建一个样式,将自定义文本框模板转换为透明背景并插入下划线

在我看来,最好的方法是尝试创建一个usercontrolhavelabel属性,您可以在需要时动态设置textboxlabel

我只是创建了一个:

namespace Test
{
    public partial class CustomTextbox : UserControl
    {
        public readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(CustomTextbox), null);
        public readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CustomTextbox), null);

        /// <summary>
        /// Get/set label
        /// </summary>
        public string Label
        {
            get
            {
                return (string)GetValue(LabelProperty);
            }
            set
            {
                SetValue(LabelProperty, value);
            }
        }

        /// <summary>
        /// Get/set text property
        /// </summary>
        public string Text
        {
            get
            {
                return (string)GetValue(TextProperty);
            }
            set
            {
                SetValue(TextProperty, value);
            }
        }

        public CustomTextbox()
        {
            InitializeComponent();

            DataContext = this;
        }
    }
}
名称空间测试
{
公共部分类CustomTextbox:UserControl
{
public readonly dependencProperty LabelProperty=dependencProperty.Register(“标签”、typeof(字符串)、typeof(自定义文本框)、null);
public readonly dependencProperty TextProperty=dependencProperty.Register(“Text”、typeof(string)、typeof(CustomTextbox)、null);
/// 
///获取/设置标签
/// 
公共字符串标签
{
得到
{
返回(字符串)GetValue(LabelProperty);
}
设置
{
SetValue(LabelProperty,value);
}
}
/// 
///获取/设置文本属性
/// 
公共字符串文本
{
得到
{
返回(字符串)GetValue(TextProperty);
}
设置
{
设置值(TextProperty,value);
}
}
公共自定义文本框()
{
初始化组件();
DataContext=this;
}
}
}
XAML:


崩溃
看得见的
崩溃
看得见的
使用:

<local:CustomTextbox Label="label:" Text="text"></local:CustomTextbox>