0

我想知道如何在按钮中访问我的进度条。

按钮使用的控件模板为:

    <ControlTemplate x:Key="ButtonWithProgressBarControlTemplate" TargetType="{x:Type Button}">
    <Grid OpacityMask="Black">
        <Rectangle x:Name="rectangle" Fill= "{TemplateBinding Background}" RadiusX="8" RadiusY="8" Margin="0,0,0,0" OpacityMask="Black">
            <Rectangle.Effect>
                <DropShadowEffect ShadowDepth="2" />
            </Rectangle.Effect>
        </Rectangle>
        <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RenderTransformOrigin="0.5,0.5">
        </ContentPresenter>
        <ProgressBar Name="buttonProgressBar" HorizontalAlignment="Left" Height="11" Margin="5,46,0,0" VerticalAlignment="Top" Width="150"/>
    </Grid>
</ControlTemplate>

我试过这个返回null的C#代码:

ProgressBar progressBar = button.Template.FindName("buttonProgressBar", button) as ProgressBar;

这是基于在 StackOverflow 上找到的其他答案,所以我希望它很简单(但我没有看到)。

4

0 回答 0