我的代码更改属性不起作用,我完全不知道什么是错的,但也许你这样做.
这是我的代码的简化示例,它重现了错误.这是我的Xaml代码:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="MyButton"
Height="100"
Width="300"
Content="Click"
FontSize="40"
FontWeight="Bold"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="Red" Click="MyButton_Click"/>
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Blue">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyButton"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="Aqua"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud)
这是Code-Behind:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void MyButton_Click(object sender, RoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Blue", true);
}
}
Run Code Online (Sandbox Code Playgroud)
理论上,这应该在点击时将Button-Color更改为"Aqua",但没有任何反应.
c# xaml visual-studio-2010 visualstatemanager windows-runtime
我需要将sql-table与DataTable(这是SQL表的修改副本)中的数据同步.我想更新/删除/插入差异,所以我需要比较两者并找到查询值(在我的案例ID中)和更改类型.有没有一种有效的方法,也许是通过一些预设的方法?我希望尽可能少访问.
我需要格式化UWP-DatePicker.我想得到的是一个常见的DatePicker,它适合在网格中.
以下是我在GridColumn中嵌入DatePicker的方法:
<Grid Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DatePicker Grid.Column="0"
HorizontalAlignment="Left"
MonthFormat="{}{month.abbreviated(3)}"
Date="{Binding AppointmentStartDateProxy, Mode=TwoWay}"
DateChanged="DatePicker_DateChanged"
Style="{StaticResource DatePickerStyle1}">
<DatePicker.IsEnabled>
<Binding Path="Closed" Converter="{StaticResource negationConverter}"/>
</DatePicker.IsEnabled>
</DatePicker>
</Grid>
Run Code Online (Sandbox Code Playgroud)
以下是StyleTemplate的"关键"更改:
<Style x:Key="DatePickerStyle1" TargetType="DatePicker">
<.../>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DatePicker">
<StackPanel x:Name="LayoutRoot" Margin="{TemplateBinding Padding}" HorizontalAlignment="Stretch" >
<ContentPresenter x:Name="HeaderContentPresenter"
x:DeferLoadStrategy="Lazy"
Visibility="Collapsed"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Margin="0,0,0,8"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
AutomationProperties.AccessibilityView="Raw" />
<Button x:Name="FlyoutButton"
HorizontalAlignment="Left"
Style="{StaticResource DatePickerFlyoutButtonStyle}"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
IsEnabled="{TemplateBinding IsEnabled}"
HorizontalContentAlignment="Stretch" />
Run Code Online (Sandbox Code Playgroud)
设置Style.Setter.Value.ControlTemplate.StackPanel.Button.HorizontalAlignment ="Left"时,我的DatePicker不会填充其父控件:

设置Style.Setter.Value.ControlTemplate.StackPanel.Button.HorizontalAlignment ="Strech"时,我的DatePicker与其父控件重叠:

当我将StyleTemplates LayoutRoot从StackPanel更改为Grid时,此行为也保持不变.
根据我的理解,RootLayout-Control应该从包含DatePicker的Grid继承它的大小,而Button应该从RootLayout获得它的大小,结果是在我的GridColumn中.
编辑:
当仅将DatePickers …
我需要从TimePicker-Controll Flyout中删除底部按钮.这种风格做到了,但我无法看到魔法发生在哪里:
<Style x:Key="TimePickerStyle1" TargetType="TimePicker">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TimePicker">
<Border x:Name="LayoutRoot"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0">
<Grid Margin="{TemplateBinding Padding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentPresenter x:Name="HeaderContentPresenter"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FlowDirection="{TemplateBinding FlowDirection}"
FontWeight="{ThemeResource TimePickerHeaderThemeFontWeight}"
Foreground="{ThemeResource TimePickerHeaderForegroundThemeBrush}" />
<StackPanel Grid.Row="1"
Margin="0,0,47,0"
Background="#FFFBFBFB"
Orientation="Horizontal">
<Border x:Name="FirstPickerHost" BorderBrush="#FFFBFBFB">
<ComboBox x:Name="HourPicker"
MinWidth="50"
Background="#FFFBFBFB" …Run Code Online (Sandbox Code Playgroud) 我想将 XDocument 转换为一个类。通常我使用 xsd-tool 创建我的类,但它似乎在 windows-phone-8 中不受支持。那么最常用的方法是什么,特别是如果我不需要原始 XDocument 中的所有信息?
这是我原来的 xml:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<request>
<type>City</type>
<query>Frankfurt, Germany</query>
</request>
<current_condition>
<observation_time>02:37 PM</observation_time>
<temp_C>17</temp_C>
<temp_F>63</temp_F>
<weatherCode>116</weatherCode>
<weatherIconUrl>
<![CDATA[http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png]]>
</weatherIconUrl>
<weatherDesc>
<![CDATA[Partly Cloudy ]]>
</weatherDesc>
<windspeedMiles>7</windspeedMiles>
<windspeedKmph>11</windspeedKmph>
<winddirDegree>270</winddirDegree>
<winddir16Point>W</winddir16Point>
<precipMM>0.1</precipMM>
<humidity>83</humidity>
<visibility>10</visibility>
<pressure>1009</pressure>
<cloudcover>50</cloudcover>
</current_condition>
<weather>
<date>2014-10-14</date>
<tempMaxC>19</tempMaxC>
<tempMaxF>67</tempMaxF>
<tempMinC>9</tempMinC>
<tempMinF>48</tempMinF>
<windspeedMiles>7</windspeedMiles>
<windspeedKmph>12</windspeedKmph>
<winddirection>SSW</winddirection>
<winddir16Point>SSW</winddir16Point>
<winddirDegree>203</winddirDegree>
<weatherCode>113</weatherCode>
<weatherIconUrl>
<![CDATA[http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png]]>
</weatherIconUrl>
<weatherDesc>
<![CDATA[Sunny]]>
</weatherDesc>
<precipMM>0.4</precipMM>
</weather>
<weather>
<date>2014-10-15</date>
<tempMaxC>19</tempMaxC>
<tempMaxF>67</tempMaxF>
<tempMinC>12</tempMinC>
<tempMinF>53</tempMinF>
<windspeedMiles>7</windspeedMiles>
<windspeedKmph>12</windspeedKmph>
<winddirection>SW</winddirection>
<winddir16Point>SW</winddir16Point>
<winddirDegree>233</winddirDegree>
<weatherCode>113</weatherCode>
<weatherIconUrl>
<![CDATA[http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png]]>
</weatherIconUrl>
<weatherDesc> …Run Code Online (Sandbox Code Playgroud) 我有一个LINQ查询,如下所示:
var query = from produkt in Entity.ProduktCollection.produktCollection
let p = produkt as Entity.Produkt
from version in p.version
let v = version as Entity.Version
from customer in v.customerCollection
let c = customer as Entity.Customer
from fehler in v.fehlerCollection
let f = fehler as Entity.Fehler
where f.id == GetGuid();
select p;
Run Code Online (Sandbox Code Playgroud)
但我真正需要的是一种方法来使f加号属性和p变量,所以我可以将它们更改为其他所有可能的组合,例如:
where c.name == "frank"
select f;
Run Code Online (Sandbox Code Playgroud)
要么
where p.id == GetGuid2()
select c;
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?据我所知,无法在from/ let-part和where/ select-part 之间的查询中插入switch-case块.
我想创建一个具有多个状态的类对象,每次只能有一个状态.例如:
班级飞机有三个条件:飞行,驾驶,站立
我喜欢这样的条件:
Plane boeing747 = new Plane;
boeing747.State = flying
Run Code Online (Sandbox Code Playgroud)
要么
boeing747.State.flying = true;
if(boeing747.State.flying == true);
console.writeline("it flyes");
else if(boeing747.State.driving == true)
console.writeline("it drives");
else
console.writeline("nothing goes");
// console reads: "it flyes"
boeing747.State.driving = true;
if(boeing747.State.flying == true);
console.writeline("it flyes");
else if(boeing747.State.driving == true)
console.writeline("it drives");
else
console.writeline("nothing goes");
// console reads: "it drives"
Run Code Online (Sandbox Code Playgroud) c# properties object visual-studio-2010 conditional-statements
c# ×7
xaml ×3
uwp ×2
.net ×1
class ×1
datatable ×1
datepicker ×1
linq ×1
linq-to-xml ×1
object ×1
properties ×1
sql ×1
xml ×1