Microsoft的unit converter starter kit爲其Windows 7手機生成帶有XAML的鍵盤,如下所示。顯然噸複製和粘貼。使用XAML時避免複製和粘貼
問題:
1)MSFT是否認真寫這種方式?
2)真的嗎?
3)有沒有一種健全的方式來寫這樣的東西?
4)有誰知道代碼示例說明了這種理智的方式嗎?
<StackPanel Orientation="Vertical">
<TextBlock x:Name="textBlockCategory"
Text="{Binding Path=UppercasedCategory}"
Margin="23,24,0,0"
FontSize="{StaticResource PhoneFontSizeMedium}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" />
<StackPanel x:Name="spInput"
Orientation="Vertical"
Margin="0,0,24,0" >
<TextBlock x:Name="textBlockInputValue"
Text="{Binding Path=UpperUnitValue}"
Height="80" Margin="0,2,0,0"
TextAlignment="Right"
FontSize="{StaticResource PhoneFontSizeExtraExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" />
<TextBlock x:Name="textBlockInputUnit"
Text="{Binding Path=UpperUnitName}"
Height="34" TextAlignment="Right" Margin="0,2,0,0"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"
Foreground="{StaticResource PhoneAccentBrush}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}" />
</StackPanel>
<StackPanel x:Name="spResult"
Orientation="Vertical"
Margin="0,-4,24,0" >
<TextBlock x:Name="textBlockResultValue"
Text="{Binding Path=LowerUnitValue}"
Height="80" TextAlignment="Right" Margin="0,-4,0,0"
FontSize="{StaticResource PhoneFontSizeExtraExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{StaticResource PhoneSubtleBrush}"/>
<TextBlock x:Name="textBlockResultUnit"
Text="{Binding Path=LowerUnitName}"
Height="34" TextAlignment="Right" Margin="0,2,0,0"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"
Foreground="{StaticResource PhoneAccentBrush}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}" />
</StackPanel>
<StackPanel x:Name="spSummary" >
<TextBlock x:Name="textBlockSummary"
Text="{Binding Path=Summary}"
Height="30" TextAlignment="Center" Margin="0,18,0,0"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneSubtleBrush}"
FontFamily="{StaticResource PhoneFontFamilyNormal}" />
</StackPanel>
<StackPanel x:Name="spKeypad" Orientation="Vertical" HorizontalAlignment="Right">
<StackPanel x:Name="spKeypadRow1" Orientation="Horizontal">
<Button x:Name="btnKeypadKey7"
Content="7"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource KeypadButtonFontSize}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey8"
Content="8"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource KeypadButtonFontSize}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey9"
Content="9"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource KeypadButtonFontSize}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKeyCancel"
Height="84" Margin="6" Width="108"
Style="{StaticResource btnKeypadKeyCancelStyle}"
Background="{StaticResource PhoneDisabledBrush}"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickClear" />
</StackPanel>
<StackPanel x:Name="spKeypadRow2" Orientation="Horizontal">
<Button x:Name="btnKeypadKey4"
Content="4"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey5"
Content="5"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey6"
Content="6"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKeyBack"
Height="84" Margin="6" Width="108"
Style="{StaticResource btnKeypadKeyBackStyle}"
Background="{StaticResource PhoneDisabledBrush}"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickBack" />
</StackPanel>
<StackPanel x:Name="spKeypadRow3" Orientation="Horizontal">
<Button x:Name="btnKeypadKey1"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Content="1"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey2"
Content="2"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKey3"
Content="3"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKeyPlusMinus"
Height="84" Margin="6" Width="108"
Style="{StaticResource btnKeypadPlusMinusStyle}"
Background="{StaticResource PhoneDisabledBrush}"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickSign" />
</StackPanel>
<StackPanel x:Name="spKeypadRow4" Orientation="Horizontal">
<Button x:Name="btnKeypadKey0"
Content="0"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="228"
Style="{StaticResource KeypadButtonStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadKeyPoint"
Content="{Binding Path=CurrentCulture.NumberFormat.NumberDecimalSeparator, Source={StaticResource Resources}}"
Background="{StaticResource PhoneInactiveBrush}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="84" Margin="6" Width="108"
Style="{StaticResource btnKeypadPointStyle}"
FontSize="{StaticResource KeypadButtonFontSize}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickNumber" />
<Button x:Name="btnKeypadSwitchSourceTargetUnit"
Height="84" Margin="6" Width="108"
Style="{StaticResource KeypadButtonStyle}"
Background="{StaticResource PhoneDisabledBrush}"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Click="OnClickSourceTargetUnit">
<Image Source= "{Binding ConversionImageSource}"/>
</Button>
</StackPanel>
</StackPanel>
</StackPanel>
你想達到什麼目的? XAML看起來像一個自定義鍵盤,而不是內置的鍵盤。除了在內置鍵盤和輸入範圍之間進行選擇外,這將是獲得完整定製鍵盤的唯一方法。 – 2011-04-05 02:19:21
我想製作自定義鍵盤而不使用複製和粘貼嘉豪。恐怕我是一個XAML newb,但在其他語言中,我會使用一些循環來避免重複使用相同的代碼,並且一次又一次地重複更改。 – 2011-04-05 02:22:56
您使用設計器來生成這種措詞。 VS或Expression Blend中的WPF設計器。或者你僱用的人爲你做,所以看起來不錯。 – 2011-04-05 02:41:17