Click here to Skip to main content
15,921,622 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Learning WPF Pin
Pete O'Hanlon16-Nov-08 11:18
mvePete O'Hanlon16-Nov-08 11:18 
QuestionDataGrid Pin
VisualLive16-Nov-08 5:33
VisualLive16-Nov-08 5:33 
QuestionAdvanced masking - Interlacing 3 video inputs into a single image [modified] Pin
Graeme_Grant16-Nov-08 2:14
mvaGraeme_Grant16-Nov-08 2:14 
AnswerRe: Advanced masking - Interlacing 3 video inputs into a single image Pin
Insincere Dave16-Nov-08 8:57
Insincere Dave16-Nov-08 8:57 
GeneralRe: Advanced masking - Interlacing 3 video inputs into a single image Pin
Graeme_Grant16-Nov-08 9:39
mvaGraeme_Grant16-Nov-08 9:39 
GeneralRe: Advanced masking - Interlacing 3 video inputs into a single image Pin
Insincere Dave18-Nov-08 5:56
Insincere Dave18-Nov-08 5:56 
GeneralRe: Advanced masking - Interlacing 3 video inputs into a single image [modified] Pin
Graeme_Grant19-Nov-08 1:35
mvaGraeme_Grant19-Nov-08 1:35 
QuestionWPF Binding to an attached property from a DataTemplate [modified] Pin
Mark Salsbery14-Nov-08 13:13
Mark Salsbery14-Nov-08 13:13 
Is there a good way to bind an element created through a DataTemplate to
an attached property?

Please refer to this post[^] for full source code
(scroll down to around the smiley)...

Elements are created through a DataTemplate and end up as children of a Grid.

The data has Row and Col properties that need to be bound to the Grids Row and
Column attached properties.

The most obvious binding (to me) would be something like this:
<DataTemplate DataType="{x:Type local:Obs}">
    <Button <code>Grid.Row="{Binding Path=Row}" Grid.Column="{Binding Path=Col}"</code> Click="Button_Click">
        <Button.Style>
            <Style TargetType="{x:Type Button}" >
                <Setter Property="Content" Value="{Binding Path=Name}"/>
                <Setter Property="Width" Value="50"/>
                <Setter Property="Height" Value="Auto"/>
                <Setter Property="Margin" Value="2"/>
                <Setter Property="Background" Value="#FFBBBB00"/>
                <Setter Property="Foreground" Value="#FF000000"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Status}" Value="On">
                        <Setter Property="Background" Value="#FFFFFF00"/>
                        <Setter Property="Foreground" Value="#FFFF0000"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
</DataTemplate>

but it doesn't work, I assume because the element isn't yet a child
of the grid at the time the binding is created.

Based on that assumption, I figured I needed an event of some kind to give me a chance to
do the binding once the created element is a child of the grid.

As seen in the code, my workaround was to override ArrangeOverride() on the Grid
and programatically create the binding there. That works, but I hate it Smile | :)

Is there a better way?

I'd love to do it completely in XAML, but I'm not smart enough yet.

Thanks!
Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

modified on Friday, November 14, 2008 7:23 PM

AnswerRe: WPF Binding to an attached property from a DataTemplate Pin
Timmy Kokke14-Nov-08 13:46
Timmy Kokke14-Nov-08 13:46 
GeneralRe: WPF Binding to an attached property from a DataTemplate Pin
Mark Salsbery14-Nov-08 14:20
Mark Salsbery14-Nov-08 14:20 
GeneralRe: WPF Binding to an attached property from a DataTemplate Pin
Timmy Kokke14-Nov-08 22:10
Timmy Kokke14-Nov-08 22:10 
GeneralRe: WPF Binding to an attached property from a DataTemplate [modified] Pin
Mark Salsbery15-Nov-08 5:36
Mark Salsbery15-Nov-08 5:36 
AnswerRe: WPF Binding to an attached property from a DataTemplate Pin
Gideon Engelberth14-Nov-08 16:48
Gideon Engelberth14-Nov-08 16:48 
GeneralRe: WPF Binding to an attached property from a DataTemplate Pin
Mark Salsbery15-Nov-08 6:40
Mark Salsbery15-Nov-08 6:40 
QuestionSWF Player in WPF Pin
ctrlnick14-Nov-08 10:25
ctrlnick14-Nov-08 10:25 
AnswerRe: SWF Player in WPF Pin
Pete O'Hanlon14-Nov-08 10:32
mvePete O'Hanlon14-Nov-08 10:32 
GeneralRe: SWF Player in WPF Pin
ctrlnick14-Nov-08 10:54
ctrlnick14-Nov-08 10:54 
QuestionDo we have a something like MASK effect (in SwishMax or Flash) in WPF? Pin
Mohammad Dayyan14-Nov-08 10:14
Mohammad Dayyan14-Nov-08 10:14 
AnswerRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Pete O'Hanlon14-Nov-08 10:43
mvePete O'Hanlon14-Nov-08 10:43 
GeneralRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Mohammad Dayyan14-Nov-08 10:48
Mohammad Dayyan14-Nov-08 10:48 
GeneralRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Pete O'Hanlon14-Nov-08 11:04
mvePete O'Hanlon14-Nov-08 11:04 
GeneralRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Mohammad Dayyan14-Nov-08 11:08
Mohammad Dayyan14-Nov-08 11:08 
GeneralRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Pete O'Hanlon14-Nov-08 11:10
mvePete O'Hanlon14-Nov-08 11:10 
JokeRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Mark Salsbery15-Nov-08 7:02
Mark Salsbery15-Nov-08 7:02 
GeneralRe: Do we have sth like MASK effect (in SwishMax or Flash) in WPF? Pin
Pete O'Hanlon15-Nov-08 8:52
mvePete O'Hanlon15-Nov-08 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.