我正在通过控制模板制作进度条。我已经在文件名library.xaml
中定义了控件模板并在library.cs
和main.xaml
中处理了它的事件我已经定义了进度条,我想改变进度的宽度但是我无法访问来自main.xaml.cs
中控件模板的矩形。
这是我的所有文件快照..
main.xaml
<Window x:Class="custom_template.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="1200">
<Grid>
<ProgressBar Style="{StaticResource ResourceKey=my_progressbar_primary}" Margin="385,176,307,122" Width="500"/>
</Grid>
</Window>
library.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="custom_template.library">
<Style TargetType="Rectangle" x:Key="style_shadow_top">
<Setter Property="Fill">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,0.5">
<GradientStop Color="#dddddd" Offset="0.25"></GradientStop>
<GradientStop Color="#F5F5F5" Offset="0.75"></GradientStop>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Rectangle" x:Key="style_shadow_top_primary">
<Setter Property="Fill">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,0.5">
<GradientStop Color="#76b9f4" Offset="0.25"></GradientStop>
<GradientStop Color="#428bca" Offset="0.75"></GradientStop>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="my_progressbar_primary">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
<Rectangle x:Name="a" HorizontalAlignment="Left" Height="20px" VerticalAlignment="Top" Width="{TemplateBinding Width}" Stroke="#ddd" ClipToBounds="True" RadiusX="3" RadiusY="3" Style="{StaticResource style_shadow_top}">
</Rectangle>
<Rectangle Height="20" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top" RadiusX="3" RadiusY="3" Style="{StaticResource style_shadow_top_primary}">
</Rectangle>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
library.cs
namespace custom_template
{
partial class library
{
private void mouseenter_rect(object sender, MouseEventArgs e)
{
((Rectangle)sender).Width++;
}
}
}
问题:如何访问main.xaml.cs中library.xaml和library.cs中的所有元素