我正在使用材料设计工具包来显示弹出的代码。我是跟随从这个github:https://github.com/Keboo/ShowMeTheXAML的参考弹出,有一个复制按钮。但它是残废的。我想我是不是错过了什么!如果有人使用这个工具包并面对这个问题,可以提出一个解决方案。
<showMeTheXaml:XamlDisplay Grid.Row="0" Grid.Column="0" UniqueKey="XamlNormalTextBoxStyle">
<TextBox Style="{StaticResource NormalTextBoxStyle}"
TextAlignment="Center"
Width="230"
Margin="0,30"
Text="This is the standard usage of textbox"/>
</showMeTheXaml:XamlDisplay>
<ControlTemplate TargetType="smtx:XamlDisplay">
<DockPanel>
<materialDesign:PopupBox DockPanel.Dock="Right"
IsTabStop="False" Padding="10" StaysOpen="True" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="PopupBox">
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon Kind="Xml" Cursor="Hand" ToolTip="View XAML"
Foreground="{DynamicResource PrimaryHueDarkBrush}"
Background="Transparent"
Margin="3">
<materialDesign:PackIcon.Style>
<Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}">
<Setter Property="Opacity" Value="0.4" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon>
</materialDesign:PopupBox.ToggleContent>
<Border MaxHeight="600" MaxWidth="800">
<DockPanel>
<Button
Margin="0 10 0 0"
Tag="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="Right"
Command="Copy"
CommandParameter="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
Content="_COPY"
DockPanel.Dock="Bottom"
Style="{StaticResource MaterialDesignRaisedButton}">
</Button>
<avalonedit:TextEditor Document="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TextDocumentValueConverter}}"
Style="{StaticResource AvalonTextEditorXamlDisplay}" />
</DockPanel>
</Border>
</materialDesign:PopupBox>
<Grid>
<AdornerDecorator>
<Border BorderBrush="{DynamicResource SecondaryHueMidBrush}" Opacity=".4" Margin="-5">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderThickness" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=PopupBox, Path=IsPopupOpen}" Value="True">
<Setter Property="BorderThickness" Value="5" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</AdornerDecorator>
<ContentPresenter />
</Grid>
</DockPanel>
</ControlTemplate>发布于 2022-01-10 05:43:58
我将按钮的代码段替换为:
<DockPanel>
<materialDesign:Badged
x:Name="CopyBadge" BadgeColorZoneMode="PrimaryDark"
DockPanel.Dock="Bottom"
HorizontalAlignment="Right">
<Button
Style="{StaticResource MaterialDesignRaisedLightButton}"
Tag="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
Click="CopyButton_OnClick"
Content="Copy"/>
</materialDesign:Badged>
<avalonedit:TextEditor Document="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TextDocumentValueConverter}}"
Style="{StaticResource AvalonTextEditorXamlDisplay}" />
</DockPanel>并在app.xaml.cs中为单击事件添加了一个处理程序,如下所示:
private void CopyButton_OnClick(object sender, RoutedEventArgs e)
{
var xamlValue = ((Button)sender).Tag;
Clipboard.SetText(xamlValue.ToString());
}它正在如预期的那样运作。
https://stackoverflow.com/questions/70593258
复制相似问题