开发者

bind the date of the DatePicker to ConverterParameter

I'm trying to mark Names in a ComboBox based on a Date from a DatePicker using a converter class.

My current problem is I don't know how to bind the date of the DatePicker to the "ConverterParameter". Any suggestions?

(probably more errors in my code but i'm stuck at this point)

<Page.Resources>  
    <Style TargetType="ComboBoxItem" x:Key="combostyle">

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <ControlTemplate.Resources>
                        <src:ColorFromMagazijnierIdConverter x:Key="conv" />
                    </ControlTemplate.Resources>

                    <Grid ToolTip="{Binding Converter={StaticResource conv}, ConverterParameter={ BIND THIS TO THE DATEPICKER DATE }, Mode=OneWay}">
                        <Rectangle x:Name="MarkedItemBackground" IsHitTestVisible="False" Fill="#80FF0000" />
                        <!--...-->
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Converter={StaticResource conv}}"
                                         Value="{x:Null}">
                            <Setter TargetName="MarkedItemBackground" 
                                        Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Page.Resources>
<Grid Margin="10,10,10,0" Name="rootGrid">
    <ComboBox Name="collectMagazijnierComboBox"
              DisplayMemberPath="User.Name"
              ItemContainerStyle="{DynamicResource ResourceKey=combostyle}"/>
    <DatePicker Name="collectDatePicker" />
开发者_运维问答</Grid>


The ConverterParameter property cannot be the target of a binding. Only a DependencyProperty of a DependencyObject can be the target of a binding.

You'll need to use a MultiBinding:

<Grid>
    <Grid.ToolTip>
        <MultiBinding Converter="{StaticResource conv}" Mode="OneWay">
            <Binding /> <!-- this mimics your current binding to the datacontext itself -->
            <Binding ElementName="collectDatePicker" Path="SelectedDate" />
        </MultiBinding>
    </Grid.ToolTip>

    <Rectangle x:Name="MarkedItemBackground" IsHitTestVisible="False" Fill="#80FF0000" />

    <!--...-->

</Grid>

You'll then need to rewrite your ColorFromMagazijnierIdConverter converter to implement the IMultiValueConverter interface instead, in which you can access both values.

Although, I'm not 100% sure whether you can reference the collectDatePicker by ElementName from within the style resource like that. But sure you can play around with it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜