小编Mat*_*hew的帖子

如何从页面中的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
查看次数

如何在视野中改变图像的前景色

我有一个Image和TextBlock的水平StackPanel.我需要做的是将两者的前景改为某种颜色.我可以使用Foreground属性轻松更改TextBlock,但我不确定如何使用Image执行此操作.该图像只是一个基本的应用程序图标.

<StackPanel Orientation="Horizontal">
    <Image Source="/Assets/Icons/appbar.book.perspective.png" Width="50" Height="50" Margin="-8,0,-6,0"/>
    <TextBlock Text="BOOK" VerticalAlignment="Center" Foreground="Blue"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

xaml styles image windows-phone-7 windows-phone-8

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

Bootstrap 表单验证在不需要输入时以绿色突出显示标签文本?

我的Bootstrap 4 表单验证发生了一件奇怪的事情,其中两个单选按钮在表单验证时将其标签的前景更改为绿色。如果表单无效,标签不会变为红色。无论哪种方式,它们都应该保留其黑色前景,因为单选按钮输入required不像我的其他表单元素那样具有与它们关联的属性。为什么它们会变成绿色,我该如何防止或停止在这两个实体上进行表单验证?

索引.html

<form id="signup-form" novalidate>

<div class="form-group">
  <h1>Sign Up</h1>
  <p>Use this form to enter your name and email to sign up.</p>
</div>

<!-- Name -->
<div class="form-group">
  <div class="row">
    <div class="col">
      <label for="firstNameInput">Name</label>
      <input type="text" class="form-control" id="firstNameInput" placeholder="First name" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col">
      <label for="lastNameInput">Last</label>
      <input type="text" class="form-control" id="lastNameInput" placeholder="Last name" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
  </div>
</div>

<!-- Email -->
<div class="form-group">
  <label for="emailAddressInput">Email address</label>
  <input …
Run Code Online (Sandbox Code Playgroud)

html javascript validation twitter-bootstrap bootstrap-4

4
推荐指数
1
解决办法
3260
查看次数

如何在按下时更改应用程序栏按钮的颜色

一个有趣的问题,我想知道是否有可能将Windows Phone 8中的应用程序栏按钮设置为使用除当前强调颜色之外的其他颜色作为按下时按钮的背景.我目前正在我的测试应用程序中创建我的应用程序栏.有什么建议怎么做?我还没有在任何地方在线找到资源.基本上我现在拥有的是一个非常简单的应用栏,用于测试目的.

MainPage.xaml.cs中

private void BuildLocalizedApplicationBar()
{
    // Set the page's ApplicationBar to a new instance of ApplicationBar.
    ApplicationBar = new ApplicationBar();

    // Create a new button and set the text value to the localized string from AppResources.
    ApplicationBarIconButton newButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/new.png", UriKind.Relative));
    newButton.Text = "new";
    newButton.Click += newButton_Click;
    ApplicationBar.Buttons.Add(newButton);
}
Run Code Online (Sandbox Code Playgroud)

c# application-bar windows-phone-8

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

如何获取ListPicker的选定项目

我想确定当前在ListPicker中选择的项目的名称.我不确定在SelectionChanged事件中要做什么来获取项目的名称.

XAML

<Grid.Resources>
        <DataTemplate x:Name="PickerItemTemplate">
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </Grid.Resources>

<toolkit:ListPicker x:Name="ThemeListPicker" Header="{Binding Path=LocalizedResources.SettingsPage_ThemeListPicker_Header, Source={StaticResource LocalizedStrings}}"
                                        ItemTemplate="{StaticResource PickerItemTemplate}"
                                        SelectionChanged="ThemeListPicker_SelectionChanged"/>
Run Code Online (Sandbox Code Playgroud)

XAML.CS

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

        themeList = new List<Theme>();
        themeList.Add(new Theme() { Name = "light" });
        themeList.Add(new Theme() { Name = "dark" });
        ThemeListPicker.ItemsSource = themeList;
    }

private void ThemeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        //get the name of the current item in the listpicker?
    }
Run Code Online (Sandbox Code Playgroud)

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

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

使用Javascript / jQuery进行Bootstrap 4表单验证

我是Web开发的新手,正在尝试建立练习表格来学习表格验证。我正在遵循Bootstrap的“自定义样式” 文档来处理那些使用屏幕阅读器的可访问性问题,并通过不同的浏览器对用户的验证外观进行标准化。

我已经建立了一个基本形式,并试图使用jQuery创建一个JavaScript函数来处理验证。我感觉自己快要到了,但是在Bootstrap演示显示时仍然没有验证工作。

index.html

<form id="signup-form" novalidate>

  <div class="form-group">
    <h1>Sign Up</h1>
    <p>Use this form to enter your name and email to sign up.</p>
  </div>

  <!-- Name -->
  <div class="form-group">
    <div class="row">
      <div class="col">
        <label for="firstNameInput">Name</label>
        <input type="text" class="form-control" id="firstNameInput" placeholder="First name" required>
        <div class="valid-feedback">
          Looks good!
        </div>
      </div>
      <div class="col">
        <label for="lastNameInput">Last</label>
        <input type="text" class="form-control" id="lastNameInput" placeholder="Last name" required>
        <div class="valid-feedback">
          Looks good!
        </div>
      </div>
    </div>
  </div>

  <!-- Email -->
  <div class="form-group">
    <label for="emailAddressInput">Email address</label>
    <input type="email" class="form-control" id="emailAddressInput" …
Run Code Online (Sandbox Code Playgroud)

javascript validation jquery twitter-bootstrap bootstrap-4

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

如何更改ListBox项的SelectedItem前景文本

我在下面有以下ListBox.我不确定如何在选择项目时更改所选项目的文本块文本的前景,然后在取消选择项目时更改为原始前景色(最有可能发生在之后选择ListBox中的其他项目时)?

<ListBox Name="ListBox" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}"
                     toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" >
                    <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}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeNormal}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
Run Code Online (Sandbox Code Playgroud)

xaml listbox textblock windows-phone-7 windows-phone-8

2
推荐指数
1
解决办法
3070
查看次数

如何在 ASP.NET 中的 Layout.CSHTML 中创建下拉导航栏菜单项

我是 ASP.NET 的新手,我想弄清楚如何创建具有下拉功能的导航栏菜单项。我特别使用这个主题。在他们的示例代码中,他们演示了下拉功能,但在我的默认 MVC 应用程序中,我使用 _Layout.cshtml 创建我的导航栏。我很难找出正确的语法。

我已经section在我的 Index.cshtml 页面中实现了s,我希望第一个导航栏菜单项下拉菜单相应地转到。我怎样才能做到这一点?

索引.cshtml

<section id="item 1">...</section>
<section id="item 2">...</section>
<section id="item 3">...</section>
Run Code Online (Sandbox Code Playgroud)

_Layout.cshtml

<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            @Html.ActionLink("My Application", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                @*<li>@Html.ActionLink("Index", "Index", "Home")</li>*@
                <li class="dropdown">
                    <a class="dropdown-toggle" role="button" aria-expanded="false" data-toggled="dropdown">@Html.ActionLink("Home", "Index", "Home")</a> …
Run Code Online (Sandbox Code Playgroud)

html css asp.net asp.net-mvc navbar

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

如果首次启动应用程序,如何显示页面

我想知道如何表示是否第一次启动应用程序,或者之前已经启动了应用程序.我想这样做的原因是在使用应用程序之前显示非常简短的信息性消息,而每隔一次启动应用程序都没有显示.我会在App.xaml.cs中放置如下内容

var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("WasLaunched")) 
{
  MessageBox.Show("First time to launch");
  settings.Add("WasLaunched", true);
}
Run Code Online (Sandbox Code Playgroud)

如果(!settings.Contains("WasLaunched")导航到"第一个启动页面"而不是"主页面"?有人能指出我对这个实现的任何好的参考?

编辑**

我将WMAppManifest.xml默认页面更改为LaunchPage.xaml

<DefaultTask Name="_default" NavigationPage="LaunchPage.xaml" />
Run Code Online (Sandbox Code Playgroud)

并创建了我的UriMapper类

public class LoginUriMapper : UriMapperBase
{
    public override Uri MapUri(Uri uri)
    {
        if (uri.OriginalString == "/LaunchPage.xaml")
        {
            if (Settings.FirstLoad.Value == true)
            {
                //Navigate to Welcome Page with quick first time user info
                uri = new Uri("/Views/WelcomePage.xaml", UriKind.Relative);
            }
            else
            {
                ///Navigate to the actual Main Page
                uri = new Uri("/MainPage.xaml", UriKind.Relative);
            } …
Run Code Online (Sandbox Code Playgroud)

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

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

如何执行卡片翻转动画

我希望能够在用户点击屏幕时从设备屏幕的一半到另一半执行卡片翻转动画.我之前从未使用动画,因此我无法完成此操作.我引用了http://blogs.msdn.com/b/kevinash/archive/2011/12/21/flipping-card-animation-for-windows-phone-7-using-expression-blend.aspx但我不知道如何适当地修改解决方案.我最终需要的是能够以这种方式翻转整个牌组.

MainPage.xaml中

<phone:PhoneApplicationPage.Resources>
    <Storyboard x:Name="Storyboard1">
        <PointAnimation Duration="0:0:2" To="0.5,0.5" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="cardBack" d:IsOptimized="True"/>
        <DoubleAnimation Duration="0:0:2" To="90" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="cardBack" d:IsOptimized="True"/>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="aceSpades">
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="90"/>
            <EasingDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="aceSpades">
            <DiscreteObjectKeyFrame KeyTime="0:0:2">
                <DiscreteObjectKeyFrame.Value>
                    <Visibility>Visible</Visibility>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</phone:PhoneApplicationPage.Resources>

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="FlipCard" >
                <Storyboard >
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="cardBack">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="cardBack">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame …
Run Code Online (Sandbox Code Playgroud)

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

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

如何获取单击的ListView项目

我在点击项目时遇到问题 ListView

MainPage.xaml中

 <ListView 
                    ReorderMode="Disabled"
                    SelectionMode="Single"
                    IsItemClickEnabled="True"
                    ItemClick="Section_ItemClick"
                    ContinuumNavigationTransitionInfo.ExitElementContainer="True">

                    <ListViewItem Margin="0,0,0,10" Background="LightGray">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/Assets/Icons/1.png" Width="94" Height="94"/>
                            <TextBlock x:Uid="1" />
                        </StackPanel>
                    </ListViewItem>

                    ...
</ListView>
Run Code Online (Sandbox Code Playgroud)

MainPage.xaml.cs中

private async void Section_ItemClick(object sender, ItemClickEventArgs e)
    {
        ListViewItem itemId = ((sender as ListView).SelectedItem as ListViewItem);

        if (itemId != null)
        {
            .. do something ..
        }
        else
        {
            throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
        }
    }
Run Code Online (Sandbox Code Playgroud)

编辑**

在进一步的测试,我发现,这两个sendere是空的事件触发时?

c# xaml listview windows-phone-8.1

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