【问题标题】:Mac Style DockBar Functionality in WPFWPF 中的 Mac 样式 DockBar 功能
【发布时间】:2011-02-08 16:10:20
【问题描述】:

我正在尝试模仿 Mac 上的 DockBar 或 ObjectBar。在此过程中,我希望学习 WPF 自定义控件,并希望为我和社区创建一个可用的控件。到目前为止我有这个

<Window x:Class="WPFMacStyleTBar.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="356" Width="577">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="3">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Button Grid.Column="1" x:Name="btnHome" Background="Transparent" BorderBrush="Transparent" Margin="0,0,47,0" Foreground="Transparent">
            <Button.Content>
                <Image Source="C:\Vikram\Projects\WPFMacStyleTBar\WPFMacStyleTBar\Images\Home.png"></Image>
            </Button.Content>
        </Button>
        <Button Grid.Column="2" x:Name="btnGlobe" Background="Transparent" BorderBrush="Transparent" Margin="0,0,47,0" Foreground="Transparent">
            <Button.Content>
                <Image Source="C:\Vikram\Projects\WPFMacStyleTBar\WPFMacStyleTBar\Images\Globe.png"></Image>
            </Button.Content>
        </Button>
        <Button Grid.Column="3" x:Name="btnNotes" Background="Transparent" BorderBrush="Transparent" Margin="0,0,49,0" Foreground="Transparent">
            <Button.Content>
                <Image Source="C:\Vikram\Projects\WPFMacStyleTBar\WPFMacStyleTBar\Images\Notes.png"></Image>
            </Button.Content>
        </Button>
    </Grid>        
</Grid>

这有点初级,但我觉得对于初学者来说应该没问题。我面临的问题是即使将背景和边框设置为透明后,按钮边框仍然显示。最重要的是,我想将按钮区域裁剪为图像的区域。对于如何做到这一点,我将不胜感激。

编辑

我找到了我要找的东西here

【问题讨论】:

    标签: wpf wpf-controls custom-controls


    【解决方案1】:

    我认为换行面板 (http://msdn.microsoft.com/en-us/library/system.windows.controls.wrappanel.aspx) 将是比仅仅限制用户能够使用的按钮更明智的选择设置。

    此外,您还可以为按钮创建样式并将按钮大小绑定到图像大小(在代码隐藏中执行检查以设置最大图像大小)。

    至于不透明的按钮边框,我真的不知道为什么会发生这种情况。如果可能,请发布屏幕截图;)

    【讨论】:

    • 我一定会检查包装面板并在可能的情况下发布屏幕截图。虽然只是复制给定的 XAML 应该会让你明白我的意思。
    • 您必须为此创建自己的样式和/或 ControlTemplate....msdn.microsoft.com/en-us/library/ms745683.aspx 将帮助您开始 ;)
    • 控制模板肯定会朝着正确的方向发展。感谢您的链接,不胜感激:)。
    • 没问题的人,我自己会对这种项目感兴趣。如果您需要帮助,请在推特上给我@XDrknezz;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多