在 Silverlight 中预览资源的模板结果

发布于 2024-11-27 00:08:42 字数 6369 浏览 1 评论 0原文

我正在开发一个最初由其他人创建的项目,他们有一个 xaml 资源字典,其中包含整个解决方案中使用的所有按钮样式。

我正在重新设计解决方案中的一个窗口,它确实可以帮助我知道哪些按钮看起来像什么,这样我就知道哪些按钮可以在其他地方工作,这样我就可以搜寻适合我正在尝试制作的新按钮的样式片段。

我的问题是有超过 30 种不同的按钮样式可供查看。

有谁知道预览将样式应用于其 targetType 的结果的好方法吗?它不需要很简单,只是希望在具体情况下尽可能简单。

注意我尝试了Expression,我没有看到其中的选项,但我还没有真正尝试过它。

我现在能想到的最好的事情是创建一个仅包含一个按钮的空白窗口,然后输入我想要查看的样式,然后我就浏览直到找到我想要的内容。有人有更好的系统吗?

我在下面提供了一个样式示例,以防它有帮助,但看起来它本身有很多依赖项。我只使用 Silverlight 第 2 个月,因此完成以下 30 多个内容有点令人畏惧。

<Style  TargetType="Button" x:Key="RightButtonBarButtonStyle">
        <Setter Property="Padding" Value="15,0,15,0" />
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontFamily" Value="Segoie"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="Padding" Value="3"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid x:Name="grid" RenderTransformOrigin="0.5,0.5" Height="25">
                        <Grid.RenderTransform>
                            <CompositeTransform/>
                        </Grid.RenderTransform>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.2">
                                        <VisualTransition.GeneratedEasingFunction>
                                            <CubicEase EasingMode="EaseOut"/>
                                        </VisualTransition.GeneratedEasingFunction>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.7" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.98" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                        <DoubleAnimation Duration="0" To="0.98" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="DisabledVisualElement" d:IsOptimized="True"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused"/>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="border" BorderBrush="{StaticResource CoreButtonBorderBrush}" BorderThickness="0,1,1,1" CornerRadius="0,15,15,0"  Background="{StaticResource CoreButtonBackgroundBrush}"/>
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="10,0,10,0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Border BorderBrush="Black" BorderThickness="0" Height="1" Margin="11,1,11,0" VerticalAlignment="Top" Background="{StaticResource CoreButtonTopLineBrush}"/>
                        <Border BorderBrush="Black" BorderThickness="0" Height="1" Margin="12,0,13,-1" Background="{StaticResource CoreButtonBottomLineBrush}" VerticalAlignment="Bottom" Opacity="0.5"/>
                        <Border x:Name="DisabledVisualElement" Background="Black" IsHitTestVisible="false" Opacity="0" CornerRadius="0,15,15,0" />

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

编辑 看来我太快拒绝表达了。默认情况下(无论如何我都假设默认)程序右侧有一个资源选项卡(“属性”和“数据”旁边)。如果它没有打开,您可以转到菜单并选择“窗口”->“资源”。

从那里显示按 xaml 文件分组的所有资源,要预览样式,请按相应名称右侧的按钮。只有一个按钮类型没有正确显示(声称有重复的键名称,不明白为什么这会阻止预览,但它确实如此,所以我猜测其他复杂情况会导致类似的结果)。

我目前正在寻找 VS2010,看看是否可以找到类似的功能,但我目前怀疑是否存在,因为这似乎更像是一种表达方式。

因此,如果有人知道 Visual Studio 2010 中存在该功能,请告诉我,因为这将使我不必在开始编辑后在项目之间跳转和刷新项目。如果可以的话,我还想避免购​​买 Expression。

I am working on a project that was originally created by someone else, they have a xaml resource dictionary containing all the button styles that are used in the entire solution.

I am reworking a window within the solution and it would really help me to know which buttons look like what, both so I know which can work somewhere else and so I can scavenge pieces of a style that fit a new button I am trying to make.

My problem is that there are over 30 different button styles to look through.

Is anyone aware of a good way to preview the results of applying a style to its targetType? It doesn't need to be simple, just hopefully as simple as can be given the circumstances.

note I tried Expression, I didn't see an option in there but I haven't really experimented with it ever.

The best thing I can think of right now is to create a blank window only containing a button which I then type in the style I want to check out, and I just go through until I find what I want. Does anyone have a better system?

I am including below an example of a style, in case it helps, but it looks like it has many dependencies itself. I am only on month 2 of Silverlight so going through 30+ of the below is a bit daunting.

<Style  TargetType="Button" x:Key="RightButtonBarButtonStyle">
        <Setter Property="Padding" Value="15,0,15,0" />
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontFamily" Value="Segoie"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="Padding" Value="3"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid x:Name="grid" RenderTransformOrigin="0.5,0.5" Height="25">
                        <Grid.RenderTransform>
                            <CompositeTransform/>
                        </Grid.RenderTransform>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.2">
                                        <VisualTransition.GeneratedEasingFunction>
                                            <CubicEase EasingMode="EaseOut"/>
                                        </VisualTransition.GeneratedEasingFunction>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.7" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.98" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                        <DoubleAnimation Duration="0" To="0.98" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
                                        <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="DisabledVisualElement" d:IsOptimized="True"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused"/>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="border" BorderBrush="{StaticResource CoreButtonBorderBrush}" BorderThickness="0,1,1,1" CornerRadius="0,15,15,0"  Background="{StaticResource CoreButtonBackgroundBrush}"/>
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="10,0,10,0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Border BorderBrush="Black" BorderThickness="0" Height="1" Margin="11,1,11,0" VerticalAlignment="Top" Background="{StaticResource CoreButtonTopLineBrush}"/>
                        <Border BorderBrush="Black" BorderThickness="0" Height="1" Margin="12,0,13,-1" Background="{StaticResource CoreButtonBottomLineBrush}" VerticalAlignment="Bottom" Opacity="0.5"/>
                        <Border x:Name="DisabledVisualElement" Background="Black" IsHitTestVisible="false" Opacity="0" CornerRadius="0,15,15,0" />

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Edit
It appears I was too quick to dismiss Expression. By default (I am assuming default anyway) there is a resource tab on the right side of the program (next to Properties and Data). If it is not open you can go to menu up to and select Window->Resources.

From there is shows all your resources grouped by xaml files, to preview what the style will look like you press the button to the right of the corresponding name. Only one button type didn't appear properly (claimed there was a duplicate key name, don't see why that would prevent a preview but it does, so I am guessing other complications will cause a similar result).

I am currently looking around VS2010 to see if I can find similar functionality but I currently doubt there is, since that seems more an expression thing.

So if anyone knows of the feature being present in Visual Studio 2010 please let me know since that will save me from having to jump between projects and refresh projects once I start editing. I'd also like to avoid purchasing Expression if I can.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任谁 2024-12-04 00:08:42

看来我太快拒绝表达了。默认情况下(无论如何我都假设默认)程序右侧有一个资源选项卡(“属性”和“数据”旁边)。如果它没有打开,您可以转到菜单并选择“窗口”->“资源”。

从那里显示按 xaml 文件分组的所有资源,要预览样式,请按相应名称右侧的按钮。只有一个按钮类型没有正确显示(声称有重复的键名称,不明白为什么这会阻止预览,但它确实如此,所以我猜测其他复杂情况会导致类似的结果)。

我目前正在寻找 VS2010,看看是否可以找到类似的功能,但我目前怀疑是否存在,因为这似乎更像是一种表达方式。

因此,如果有人知道 Visual Studio 2010 中存在该功能,请告诉我,因为这将使我不必在开始编辑后在项目之间跳转和刷新项目。如果可以的话,我还想避免购​​买 Expression。

It appears I was too quick to dismiss Expression. By default (I am assuming default anyway) there is a resource tab on the right side of the program (next to Properties and Data). If it is not open you can go to menu up to and select Window->Resources.

From there is shows all your resources grouped by xaml files, to preview what the style will look like you press the button to the right of the corresponding name. Only one button type didn't appear properly (claimed there was a duplicate key name, don't see why that would prevent a preview but it does, so I am guessing other complications will cause a similar result).

I am currently looking around VS2010 to see if I can find similar functionality but I currently doubt there is, since that seems more an expression thing.

So if anyone knows of the feature being present in Visual Studio 2010 please let me know since that will save me from having to jump between projects and refresh projects once I start editing. I'd also like to avoid purchasing Expression if I can.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文