views:

45

answers:

1

I know that Binding in WPF is a really powerful feature, but I don't know if that is possible.

My window is composed of a really simple grid:

<Grid Height="593" Width="800" >
    <Grid.RowDefinitions>
        <RowDefinition Height="109*" />
        <RowDefinition Height="484*" />
    </Grid.RowDefinitions>
    <Grid.Background>
        <ImageBrush ImageSource="MenuBackground.png" />
    </Grid.Background>

    <Label Grid.Row="0" 
           HorizontalAlignment="Center" VerticalAlignment="Center" 
           FontSize="36" Foreground="Gray"
           Margin="0,15,0,0">
        Bindings Sandbox
    </Label>

    <Grid Grid.Row="1" Width="300" Height="200">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Button Grid.Row="0" Margin="5" FontSize="16">Slider and Progress Bar</Button>
        <Button Grid.Row="1" Margin="5" FontSize="16">Button2</Button>
    </Grid>
</Grid>

I want to know if it is possible to call another window (let's say defined in View1.xaml) without routing the Button.Click incode-behind?

A: 

You have a few options here.

Technically, you could make an attached property that does what you want. This would use code, but not in the code behind, so it provides a more reusable option.

Alternatively, you can use a Command instead of an event handler. This lets you bind to the command, and move the logic into your DataContext. (This, btw, is one of the "tools" that makes the MVVM pattern work correctly.) The Command could open your new View.

Reed Copsey
I like the Command option more. Thanks for pointing that out.
Padu Merloti
That's my personal preference, as well - but those are the two options I have used.
Reed Copsey
if you like it why dont you mark it up?
I__
He accepted it - that's good enough for me :)
Reed Copsey