[Winodows Phone 7控件详解]基本控件

在这里,把一些最基本的控件列出来,其实也就是没有归类的控件都放在这里了。

一.TextBlock:这个控件其实就是Label控件。

<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>

Style:设置字体、字色、大小等样式,用StaticResource方式可以绑定预设的样式。

TextWrapping:设置是否自动换行。

Text:在控件上要显示的文字。

二.CheckBox:  多选控件,通过blend工具也可以生成多种效果,另外要想将选择框加大,并不是能过设置Width,Height来完成的,而是通过RenderTransformScale来完成的。

            <CheckBox Content="CheckBox1" Height="219" HorizontalAlignment="Left" Margin="76,22,0,0" Name="checkBox1" VerticalAlignment="Top" Width="293" BorderBrush="Red" Foreground="Blue" Checked="checkBox1_Checked" Background="Gold"  />
<CheckBox Content="CheckBox2" Height="72" HorizontalAlignment="Left" Margin="143,0,0,319" Name="checkBox2" VerticalAlignment="Bottom" Checked="checkBox2_Checked" RenderTransformOrigin="0.5,0.5" BorderBrush="#BFFB2200" Foreground="#FF1008F7">
<CheckBox.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0.504"/>
<GradientStop Color="#FFF00000" Offset="1"/>
</LinearGradientBrush>
</CheckBox.Background>
<CheckBox.RenderTransform>
<CompositeTransform ScaleX="2" ScaleY="2"/>
</CheckBox.RenderTransform>
</CheckBox>

更改Height不能改变CheckBox1的大小。

三.RadioButton:单选按钮。当有多个在一起时,可以自动互斥。与多选控件一样,要想使控件变大,需要使用Transform scale来实现。

<RadioButton GroupName="Group1" Content="Group1-Item1" Checked="HandleCheck" Height="72" HorizontalAlignment="Left" Margin="115,50,0,0" Name="radioButton1" VerticalAlignment="Top" />
<RadioButton GroupName="Group1" Content="Group1-Item2" Checked="HandleCheck" Height="72" HorizontalAlignment="Left" Margin="115,128,0,0" Name="radioButton2" VerticalAlignment="Top" />
<RadioButton GroupName="Group2" Content="Group2-Item1" Height="72" HorizontalAlignment="Left" Margin="115,206,0,0" Name="radioButton3" VerticalAlignment="Top" />
<RadioButton GroupName="Group2" Content="Group2-Item2" Height="72" HorizontalAlignment="Left" Margin="115,284,0,0" Name="radioButton4" VerticalAlignment="Top" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="115,397,0,0" Name="choiceTextBlock" Text="TextBlock" VerticalAlignment="Top" />

GroupName:设置RadioButton的分组,组中互斥。

Checked:建议一组使用一个Checked事件处理程序。

private void HandleCheck(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
choiceTextBlock.Text = "You chose: " + rb.GroupName + ": " + rb.Name;
}

四.ProgressBar:  进度条控件。有两种形式,一种是显示确切进度的;另一种是不确定的,不断重复。

<ProgressBar Height="30" HorizontalAlignment="Left" Margin="12,47,0,0" Name="progressBar1" VerticalAlignment="Top" Width="460"  Value="80"/>
<ProgressBar Height="37" HorizontalAlignment="Left" Margin="8,144,0,0" Name="progressBar2" VerticalAlignment="Top" Width="460" IsIndeterminate="True" />

Value进度条的值。

IsIndeterminate:设置进度条形式,False:不重复的进度,按value值变化进度;True:重复进度条。

五.Slider:滑杆控件。可以设置水平、垂直方向。

<Slider Height="84" HorizontalAlignment="Left" Margin="12,50,0,0" Name="slider1" VerticalAlignment="Top" Width="460" Minimum="0" Maximum="100" IsDirectionReversed="True" />
<Slider Height="345" HorizontalAlignment="Left" Margin="177,140,0,0" Name="slider2" VerticalAlignment="Top" Width="110" Orientation="Vertical" Minimum="0" Maximum="100" IsDirectionReversed="True"/>

Orientation:设置滑杆方向。

IsDirectionReversed:设置Slider控件值的增加方向。

Value:设置当前值。

六.PopUp:弹出控件,可以显示到当前页的最前面。这个控件可以用来做自定义的messagebox,等待框等。前面在容器控件的时候讲过。

七.Thumb:这个控件可以通过拖动,获取连续的坐标(有点儿像笔记本上的触摸板),从而和其他控件组合使用来产生控件拖动效果。

<Canvas Margin="0,0,6,0">
<Thumb Height="121" HorizontalAlignment="Left" Margin="64,107,0,0" Name="thumb1" VerticalAlignment="Top" Width="137" DragDelta="thumb1_DragDelta"/>
<TextBlock FontSize="20" Canvas.Left="53" Canvas.Top="41" Height="47" Name="textBlock1" Text="TextBlock" Width="340" />
</Canvas>

Thumb的核心事件有:

DragStarted——当你在它上面按下鼠标左键,开始拖动时发生;
DragDelta——只要你的拖动仍在操作(没松开鼠标左键),它就会不断地发生;
DragCompleted——在拖动操作结束后发生。
private void thumb1_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
Thumb myThumb = (Thumb)sender;
double nTop = Canvas.GetTop(myThumb) + e.VerticalChange;
double nLeft = Canvas.GetLeft(myThumb) + e.HorizontalChange;

Canvas.SetTop(myThumb, nTop);
Canvas.SetLeft(myThumb, nLeft);

textBlock1.Text = "Top:" + nTop.ToString() + "\nLeft:" + nLeft.ToString();
}

 八.ListBox:相当于一个容器,可以通过ListItem来组合多个控件而得到不同功能的List。

            <ListBox Height="353" HorizontalAlignment="Left" Margin="8,62,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="100" Height="100"
Source="{Binding Source}"/>
<TextBlock Text="{Binding Text}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
        public class Item
{
public ImageSource Source { get; set; }
public string Text { get; set; }
}
            List<Item> list = new List<Item>();

Item item1 = new Item();
item1.Source = new BitmapImage(new Uri("Images/1.jpg", UriKind.Relative));
item1.Text = "1.jpg";
list.Add(item1);
//
Item item2 = new Item();
item2.Source = new BitmapImage(new Uri("Images/1.jpg", UriKind.Relative));
item2.Text = "1.jpg";
list.Add(item2);
//
listBox1.ItemsSource = list;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值