c# - AvaloniaWPF Passing a Router into a ControlTemplate - Stack Overflow

Long story short, I have an Avalonia project where I'm using the SimpleRouter library to achieve r

Long story short, I have an Avalonia project where I'm using the SimpleRouter library to achieve routing. The code is very similar to the full code example, using a ServiceCollection and I can access the HistoryRouter<ViewModelBase> router in my MainViewModel.

I also have a ControlTemplate that is meant to provide reusable functionality for some, but not all of the pages. The functionality includes going to the previous page, which means I'd like to use the router's GoBack() method for this. Unfortunately, I have absolutely no idea how to go about passing the router or the ServiceCollection into the component so I can use the method. Searching the internet has been fairly unhelpful with suggesting what I need to do.

Component example:

<Styles>
    <Style Selector="controls|MyComponent">
        <Setter Property="Template">
            <ControlTemplate>
                <StackPanel>
                    <Button>Go Back</Button>
                    <ContentPresenter Content="{TemplateBinding Content}"/>
                </StackPanel>
            </ControlTemplate>
        </Setter>
    </Style>
</Styles>

PageView example:

<UserControl x:Class="Project.Views.SomePageView">
    <StackPanel>
        <controls:MyComponent/>
        <TextBlock Text="Some Content" />
    </StackPanel>
</UserControl>

What would be the proper way to achieve something like I want without breaking any of the design patterns? Any help would be appreciated.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745254077a4618851.html

相关推荐

  • c# - AvaloniaWPF Passing a Router into a ControlTemplate - Stack Overflow

    Long story short, I have an Avalonia project where I'm using the SimpleRouter library to achieve r

    2小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信