2017-08-11 89 views
0

UWP我想設置一個按鈕樣式命令,但我的命令不火:(XAML命令裏面一個樣式

任何明顯浮現在腦海?

<Style x:Key="TimeBtnStyle" BasedOn="{StaticResource ClickBtnStyle}" TargetType="Button"> 
    <Setter Property="Command" Value="{Binding Path=vm.CommandTester}"/> 
    <Setter Property="CommandParameter" Value="{Binding Content}"/> 

    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Button"> 
       <Grid x:Name="RootGrid" Background="Transparent"> 
        <Border CornerRadius="12" Background="White" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="4"> 
         <ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ContentTransitions="{TemplateBinding ContentTransitions}"> 
         </ContentPresenter> 
        </Border> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

綁定不二傳手支持。即使這樣做,不這樣做。 –

+0

@JustinXL那麼,如何調用命令從風格? – Maf

+0

我別建議這樣做。爲什麼你需要一種風格的命令呢? –

回答

0

你可以把按鈕在一個的ContentTemplate的ContentControl中。

<DataTemplate x:Key="ItemTemplate"> 
    <Button Command="{Binding ICommand}"/> 
</DataTemplate> 

<ContentControl ContentTemplate="{StaticResource ItemTemplate}"/> 
<ContentControl ContentTemplate="{StaticResource ItemTemplate}"/> 
<ContentControl ContentTemplate="{StaticResource ItemTemplate}"/>