小编Mat*_*hew的帖子

如何实现BoolToVisibilityConverter

在我的应用程序中,我想切换StackPanel中项目的可见性.我的Stackpanel包含一个Image和一个TextBlock.如何正确使用BoolToVisibilityConverter切换TextBlock的可见性,并为用户的利益保存此设置?

目前我的情况如下,虽然我收到了一些错误.重要提示,我需要使用ApplicationBar菜单项作为单击事件来驱动TextBox可见性的切换.

编辑

尽管TextBlock的可见性未发生变化,但不再出现错误.

XAML

xmlns:common="clr-namespace:TestApp.Common"

<phone:PhoneApplicationPage.Resources>
    <common:BooleanToVisibilityConverter x:Key="BoolToVisConv" />
</phone:PhoneApplicationPage.Resources>

<ListBox Name="ListBoxEffects" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}"
                     toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" 
                         ItemContainerStyle="{StaticResource ListBoxItemStyle1}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel ItemWidth="159" ItemHeight="Auto" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical"  >
                                <Image Source="{Binding Thumbnail}" Width="155" Height="155" />
                                <TextBlock Text="{Binding Name}" Visibility="{Binding IsTextBlockVisible, Converter={StaticResource BoolToVisConv}}"  TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeNormal}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
Run Code Online (Sandbox Code Playgroud)

代码背后

private void BuildLocalizedApplicationBar()
    {
        ApplicationBar = new ApplicationBar();

        ApplicationBarMenuItem showFilterNamesMenuItem = new ApplicationBarMenuItem();
        if (Settings.ShowFilterNames.Value)
            showFilterNamesMenuItem.Text = AppResources.EditPage_EffectNames_Hide;
        else
            showFilterNamesMenuItem.Text = AppResources.EditPage_EffectNames_Show;
        showFilterNamesMenuItem.Click …
Run Code Online (Sandbox Code Playgroud)

c# xaml converter windows-phone-7 windows-phone-8

13
推荐指数
3
解决办法
2万
查看次数

如何在Windows Phone 8中更改数据透视表头模板

我希望能够在Windows Phone 8中更改Pivot Headers和Application Title的背景.从我收集的内容中,我必须创建一个针对Pivot控件的自定义样式.但是,我不确定只更改标题的背景?

我想以某种方式调整风格

<Style x:Key="MyPivotStyle" TargetType="phone:Pivot">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="phone:Pivot">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid CacheMode="BitmapCache" Grid.RowSpan="2">
                    <Grid.Background>
                        <ImageBrush ImageSource="/Assets/bg_header.png"/>
                    </Grid.Background>
                </Grid>
                <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" />
                <ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Margin="24,17,0,-7">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Assets/company_name.png" Width="213.75" HorizontalAlignment="Left" VerticalAlignment="Top" />
                        <Button HorizontalAlignment="Right" VerticalAlignment="Top" Margin="140,-20,0,35" BorderThickness="0" x:Name="btnHome">
                            <Image Source="/Assets/btnHome.png" Width="48" Height="48" ></Image>
                        </Button>
                    </StackPanel>
                </ContentPresenter>
                <controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement" Foreground="White"  Grid.Row="1"/>
                <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
            </Grid>
        </ControlTemplate>
    </Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-phone-8

12
推荐指数
1
解决办法
3万
查看次数

如何隐藏单个PivotItem的可见性

我的页面中有一些透视项目,根据应用程序是否处于试用模式,我需要显示或隐藏其中一个PivotItems.直接在XAML或C#中设置PivotItem的可见性仅隐藏PivotItem内的内容,而不是实际的PivotItem本身.我怎么能做到这一点?

在测试中,我尝试了以下两种方法

Page.xaml

<phone:PivotItem x:Name="PivotItem2" Visibility="Collapsed"
                         Header="2">
                ...
</<phone:PivotItem>
Run Code Online (Sandbox Code Playgroud)

要么

Page.xaml.cs

 protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        //Check trial state and set PivotItem
        if ((Application.Current as App).IsTrial)
        {
            PivotItem2.Visibility = Visibility.Collapsed;
        }
        else
        {
            PivotItem2.Visibility = Visibility.Visible;
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# xaml pivotitem windows-phone-8

10
推荐指数
1
解决办法
4043
查看次数

如何在Visual Studio 2013中定位WP7.1

我刚刚升级到Windows 8.1并安装了Visual Studio 2013.我正在尝试更新以前的WP7.1解决方案,但在使用VS2013打开时,我被要求更新一些内容.我选择是的,除了我在原始解决方案(内置于VS2012中)中从NuGet获得的Windows Phone Toolkit外,一切似乎都有效.更新后,我有一个迁移报告错误说Some NuGet packages were installed using a target framework different from the current target framework and may need to be reinstalled. For more information, visit http://docs.nuget.org/docs/workflows/reinstalling-packages. Packages affected: WPtoolkit.由于我的应用程序是在VS2012中针对WP7.1构建的,我认为删除和重新下载WPToolkit会起作用,但它默认以WP80为目标.我似乎无法创建一个针对7.1的Windows Phone应用程序?这有解决方案吗?

windows-phone-7 visual-studio-2012 windows-phone-8 visual-studio-2013

6
推荐指数
1
解决办法
5221
查看次数

如何更改模板中数据透视表项目标题的大小

我希望能够修改默认的数据透视表模板来更改数据透视表项标题的大小.我如何使用以下样式执行此操作

<Style x:Key="PivotStyle" TargetType="phone:Pivot">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="phone:Pivot">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid CacheMode="BitmapCache" Grid.RowSpan="2" >
                            <Grid.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Color="Transparent" Offset="0.0" />
                                    <GradientStop Color="Transparent" Offset="1.0" />
                                </LinearGradientBrush>
                            </Grid.Background>
                        </Grid>
                        <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" />
                        <ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7" />
                        <Primitives:PivotHeadersControl x:Name="HeadersListElement" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="28" …
Run Code Online (Sandbox Code Playgroud)

xaml windows-phone-8

6
推荐指数
1
解决办法
6845
查看次数

在 Amazon S3 上托管的网站不显示 Favicon

因此,我最近开始使用 Amazon S3 并构建一个小型示例 Web 应用程序。我按照教程进行操作,我的网站(包括图像)运行正常。我favicon.ico向根目录添加了一个文件,并在我的根目录中引用了该文件index.html,但无论我做什么,我都无法让该图标显示在浏览器搜索栏、选项卡或收藏夹列表中。

请注意,我使用了步骤 2.1 - 第 4 部分中教程提供的存储桶策略权限来使我的对象可公开访问,并且我还可以导航到保存我的 favicon.ico 对象的 S3 存储桶提供的链​​接,我可以看到它在浏览器中,所以我知道该链接有效。

如果链接有效,存储桶中的所有内容都可以公开访问,并且我网站的其余部分(包括图像)可以正常工作,我做错了什么?

文件结构

在此输入图像描述

索引.html

...
<!-- Favicon -->
<link rel="icon" href="favicon.ico" type="image/x-icon">
...
Run Code Online (Sandbox Code Playgroud)

亚马逊 S3 存储桶

在此输入图像描述

桶策略

在此输入图像描述

更新:我也尝试<link rel="icon" href="favicon.ico" type="image/x-icon">从我的中完全删除index.html并修改它以使其/前面有一个favicon.ico像这样的<link rel="icon" href="/favicon.ico" type="image/x-icon">无济于事。

html css favicon amazon-s3 amazon-web-services

6
推荐指数
1
解决办法
1万
查看次数

videobrush方向与手机方向不符

我试图将视频插播方向与手机的方向相匹配,但我在实施此解决方案时遇到问题.我的xaml页面设置为PortraitOrLandscape,我希望无论手机的方向如何,视频都可以正面朝上.在将方向更改if语句添加到onOrentationChanged事件之前,会出现以下情况

电话:左转,Videobrush:正面朝上

电话:Portrait,Videobrush,顺时针旋转-90

电话:右侧,Videobrush,顺时针旋转-180

XAML

<Rectangle x:Name="videoRectangle" Margin="0,0,0,0">
            <Rectangle.Fill>
                <VideoBrush x:Name="viewfinderBrush" AlignmentX="Left" AlignmentY="Top" Stretch="UniformToFill">
                    <VideoBrush.RelativeTransform>
                        <CompositeTransform x:Name="viewfinderTransform" 
                                            CenterX="0.5" CenterY="0.5"/>
                    </VideoBrush.RelativeTransform>
                </VideoBrush>                    
            </Rectangle.Fill>
        </Rectangle>
Run Code Online (Sandbox Code Playgroud)

XAML.CS

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
    {
        base.OnOrientationChanged(e);

        if (e.Orientation == PageOrientation.LandscapeLeft)
        {                //do nothing
                         //The videobrush orientation is currently right side up
        }
        if (e.Orientation == PageOrientation.Portrait)
        {
            //the videobrush is currently rotated 90 degrees counter clockwise
            this.viewfinderTransform.Rotation = this.camera.Orientation + 90.0;
        }
        if (e.Orientation == PageOrientation.LandscapeRight)
        {
            //the videobrush is currently rotated 180 degrees counter …
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-phone-7

5
推荐指数
1
解决办法
2571
查看次数

如何在Windows Phone 8中使用ProgressRing

在引用http://briandunnington.github.io/progressring-wp8.html以获得有趣的进度指示器的新实现时,我想将ProgressRing控件改编为Windows Phone 8.我不确定如何准确添加所有内容在我的应用程序的MainPage中.我所拥有的如下

MainPage.xaml中

<phone:PhoneApplicationPage.Resources>
    <!-- Default style for Windows.UI.Xaml.Controls.ProgressRing -->
    <Style TargetType="controls:ProgressRing">
        <Setter Property="Foreground" Value="{StaticResource AccentBrush}" />
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="MinHeight" Value="20" />
        <Setter Property="MinWidth" Value="20" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ProgressRing">
                    <Border x:Name="ProgressRingRoot" Background="{TemplateBinding Background}"
                BorderThickness="{TemplateBinding BorderThickness}"
                BorderBrush="{TemplateBinding BorderBrush}">
                        <Border.Resources>
                            <Style x:Key="ProgressRingEllipseStyle" TargetType="Ellipse">
                                <Setter Property="Opacity" Value="0" />
                                <Setter Property="HorizontalAlignment" Value="Left" />
                                <Setter Property="VerticalAlignment" Value="Top" />
                            </Style>
                        </Border.Resources>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="SizeStates">
                                <VisualState x:Name="Large"> …
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-phone-7 progress-bar windows-phone-8

5
推荐指数
1
解决办法
4272
查看次数

python -v命令做什么

我最近重新安装了macOS,我想检查Python的版本。我输入python -v了终端,我不确定这样做是什么?我是终端和python编程的新手。我是否意外安装了新软件?

Last login: Sun May 14 15:02:37 on ttys000
Matthews-MacBook-Pro:~ matthewkol$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py
import site # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py
import os # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py
import posixpath # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.py
import stat # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.pyc
# /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py …
Run Code Online (Sandbox Code Playgroud)

python macos terminal python-2.7 macos-sierra

5
推荐指数
2
解决办法
3803
查看次数

如何从页面中的App.xaml获取颜色值

我已经宣布了一种颜色,我将在我的应用程序中大量使用,我希望能够在页面中调用该特定颜色.这种颜色最有可能用于XAML以及后面的代码.在App.xaml我有

<Color x:Name="Blue" A="255" R="35" G="85" B="145"/>
Run Code Online (Sandbox Code Playgroud)

但是我如何在我的Page的UI和代码中调用它呢?

实际上要注意,上面在App.xaml中设置颜色会在启动时出现调试错误?

public App()
    {
        // Standard XAML initialization
        InitializeComponent(); //XamlParseException occurs here

        ...
    }
Run Code Online (Sandbox Code Playgroud)

编辑**

SolidColorBrush更新无法正常工作

我有一个Slider控件和两个在XAML中声明的ToggleSwitch控件,我希望在XAML中更改Slider前景并更改后面代码中的ToggleSwitch控件.两者都不起作用

App.xaml中

<Color x:Key="ThemeColorBlue" A="255" R="35" G="85" B="145"/>
<SolidColorBrush x:Key="ThemeBrushBlue" Color="{StaticResource ThemeColorBlue}"/>
Run Code Online (Sandbox Code Playgroud)

因此,当尝试在XAML中更改Slider控件前景时,我没有使用错误

Foreground="{StaticResource ThemeBrushBlue}"
Run Code Online (Sandbox Code Playgroud)

但是当在后面的代码中更改ToggleSwitch前景时,我得到一个错误说明 Cannot implicitly convert type 'object' to 'System.Windows.Media.Brush'

this.ToggleSwitch.SwitchForeground = Application.Current.Resources["ThemeBrushBlue"];
Run Code Online (Sandbox Code Playgroud)

c# xaml windows-phone-7 windows-phone-8

4
推荐指数
2
解决办法
6724
查看次数