码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 入门 《常用控件》

时间:2018-05-09 16:43:58      阅读:749      评论:0      收藏:0      [点我收藏+]

标签:box   save   been   属性   左侧菜单   子页面   most   标签页   control   

1.GroupBox

技术分享图片

注意: GroupBox仍然需要布局容器来放置元素。如: StackPanel面板

 <GroupBox Header="select number?">
        <StackPanel>
            <RadioButton>one</RadioButton>
            <RadioButton>two</RadioButton>
            <RadioButton>three</RadioButton>
        </StackPanel>
    </GroupBox>

 

2.TabControl

   像这种标签页控件, 在winform种非常常见, Tabpge子页面, 而在WPF种, 对应的则是TabItem类。

技术分享图片

 所示的代码示意图:

<TabControl>
        <TabItem Header="首页">
            <StackPanel>
                <Button>button1</Button>
                <Button>button2</Button>
                <Button>button3</Button>
            </StackPanel>
        </TabItem>

        <TabItem Header="第二页">
            <StackPanel>
                <Button>button4</Button>
                <Button>button5</Button>
                <Button>button6</Button>
            </StackPanel>
        </TabItem>
        
    </TabControl>

Content属性相同, TabItem的Header同样可以接收任何类型的对象。这意味着可以创建一个组合框或选项卡。在他们的页标题中包含任意图形和任意元素。如下所示:

 技术分享图片

<TabControl>
        <TabItem >
            <TabItem.Header>
                <StackPanel Orientation="Horizontal">
                    <Button Background="Transparent" BorderBrush="Transparent">?</Button>
                    <TextBox BorderBrush="Transparent">首页</TextBox>
                </StackPanel>
            </TabItem.Header>

            <StackPanel>
                <Button>button1</Button>
                <Button>button2</Button>
                <Button>button3</Button>
            </StackPanel>

        </TabItem>
    </TabControl>

 

3.Expander菜单控件

  具备标题的内容收缩控件, 在web中很普遍, 用于左侧菜单。

 

技术分享图片

 代码如下所示:

    <StackPanel>
        <Expander Header="One" Margin="5" Padding="5">
            <TextBlock TextWrapping="Wrap">Ofo has been favored by the public, even the foreign people speak highly of it. These yellow
                bikes can be found everywhere, so the people who are in a hurry can 
                use it and then reached the destination in time.</TextBlock>
        </Expander>

        <Expander Header="Two" Margin="5" Padding="5">
            <TextBlock TextWrapping="Wrap">Especially for the visitors, they can ride these bikes and then have a look at the scenery around.</TextBlock>
        </Expander>

        <Expander Header="Three" Margin="5" Padding="5">
            <TextBlock TextWrapping="Wrap">It can saves them a lot of money and the most important thing is the convenience it brings.</TextBlock>
        </Expander>

    </StackPanel>

  

4.ListBox控件

  ListBox控件是一个非常灵活的控件, 它不仅包含子元素ListBoxItem对象。而且也可以驻留其他元素, 这也就是ListBoxItem类继承于ContentControl类,从而ListBoxItem能够包含一段嵌套的内容。

 

例如, 创建一个包含普通按钮的列表。如下所示:

技术分享图片

 

 <StackPanel>
        <ListBox>
            <ListBoxItem>
                <Button>? button1</Button>
            </ListBoxItem>
        </ListBox>

        <ListBox>
            <ListBoxItem>
                <Button>? button2</Button>
            </ListBoxItem>
        </ListBox>

        <ListBox>
            <ListBoxItem>
                <Button>? button3</Button>
            </ListBoxItem>
        </ListBox>
    </StackPanel>

 

5. ProgressBar进度条

  IsIndeterminate属性设置为True, 控件则会周期性的显示一个绿色(默认)从左到右的脉冲。

 

    <Grid>
        <ProgressBar IsIndeterminate="True" Height="30"></ProgressBar>
    </Grid>

 

当然, 我们也可以通过修改Foreground 属性, 修改其滚动的颜色。如下所示

技术分享图片

    <StackPanel>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="Green" ></ProgressBar>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="Red" ></ProgressBar>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="Chocolate" ></ProgressBar>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="DarkSalmon" ></ProgressBar>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="Pink" ></ProgressBar>
        <ProgressBar Margin="2" IsIndeterminate="True" Height="30" Foreground="DodgerBlue" ></ProgressBar>
    </StackPanel>

  

 

 

 

 

  

 

WPF 入门 《常用控件》

标签:box   save   been   属性   左侧菜单   子页面   most   标签页   control   

原文地址:https://www.cnblogs.com/zh7791/p/9014957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!