【问题标题】:WPF TELERIK RADSCHEDULEVIEW Group Header Content Template BindingsWPF TELERIK RADSCHEDULEVIEW 组标题内容模板绑定
【发布时间】:2017-02-08 09:14:16
【问题描述】:

所以,我在这里要做的是在单击复选框时更改我的RadScheduleView GroupHeaderContentTemplate 的外观。此 CheckBox 绑定到我的视图模型中的 ShowPictures 属性。还有一个GroupHeaderHeight 属性来设置每个分组的最大高度。

属性定义如下:

private bool _ShowPictures;
public bool ShowPictures    
{
    get
    {
        return this._ShowPictures;
    }
    set
    {
        if (this._ShowPictures == value)
        {
            return;
        }               
        this._ShowPictures = value;
        this.RaisePropertyChanged(nameof(this.ShowPictures));               
    }
}

private int _GroupHeaderHeight;
public int GroupHeaderHeight
{
    get
    {
        return this._GroupHeaderHeight;
    }
    set
    {
        if (this._GroupHeaderHeight == value)
        {
            return;
        }

        this._GroupHeaderHeight = value;
        this.RaisePropertyChanged(nameof(this.GroupHeaderHeight));                               
    }
}

复选框代码:

<CheckBox Name="cbShowPictures" Content="Show Pictures" Grid.Column="9"
    IsChecked="{Binding ShowPictures,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

我的 RadScheduleViews 代码:

<UserControl.Resources>

<converters:DatabindingDebugConverter x:Key="DatabindingDebugConverter"/>
<BooleanToVisibilityConverter x:Key="BoolToVis"/>

<telerik:RadScheduleView x:Name="MainSchedule" 
    Grid.Row="0" 
    Margin="2" 
    TimeMarkersSource="{Binding TimeMarkers}"
    CategoriesSource="{Binding Categories}"  
    MinAppointmentHeight="25" 
    NavigationHeaderVisibility="Visible" 
    AppointmentsSource="{Binding WorkOrderTasks,Mode=TwoWay,    UpdateSourceTrigger=PropertyChanged}" 
    AppointmentCreated="MainSchedule_AppointmentCreated"
    ResourceTypesSource="{Binding ResourceTypes}" 
    AppointmentDeleted="MainSchedule_AppointmentDeleted" 
    AppointmentEdited="MainSchedule_AppointmentEdited"
    CurrentDate="{Binding FilterStart,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
    SelectedAppointment="{Binding SelectedWorkOrderTask, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
    FirstVisibleTime="8:00:00" 
    ShowAppointmentDeleteButton="False"
    ToolTipTemplate="{StaticResource AppointmentToolTipTemplate}">

        <telerik:RadScheduleView.ViewDefinitions>
            <telerik:TimelineViewDefinition MinTimeRulerExtent="1" 
                MaxTimeRulerExtent="Infinity"
                MinorTickLength="1h" 
                DayStartTime="{Binding DailyStartTime, Mode=TwoWay}"
                DayEndTime="{Binding DailyEndTime, Mode=TwoWay}"
                VisibleDays="{Binding VisibleDays, Mode=TwoWay}"                                                                        
                StretchGroupHeaders="True"
                StretchAppointments="True"/>

        <telerik:DayViewDefinition  DayStartTime="{Binding DailyStartTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                DayEndTime="{Binding DailyEndTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                VisibleDays="{Binding VisibleDays, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"                                                                   
                StretchGroupHeaders="False"
                MinTimeRulerExtent="1" 
                MaxTimeRulerExtent="Infinity"
                MinorTickLength="1h" />

         <telerik:WeekViewDefinition  DayStartTime="{Binding DailyStartTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                DayEndTime="{Binding DailyEndTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                VisibleDays="{Binding VisibleDays, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"                                                                   
                StretchGroupHeaders="False"
                MinTimeRulerExtent="1" 
                MaxTimeRulerExtent="Infinity"
                MinorTickLength="1h"/>

            <telerik:MonthViewDefinition  DayStartTime="{Binding DailyStartTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
               DayEndTime="{Binding DailyEndTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
               VisibleDays="{Binding VisibleDays, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"                                                                   
               StretchGroupHeaders="False"
               MinTimeRulerExtent="1" 
               MaxTimeRulerExtent="Infinity"/>

            <telerik:CustomViewDefinition  DayStartTime="{Binding DailyStartTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
               DayEndTime="{Binding DailyEndTime, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
               VisibleDays="{Binding VisibleDays, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"                                                                   
               StretchGroupHeaders="False"
               MinTimeRulerExtent="1" 
               MaxTimeRulerExtent="Infinity"
               MinorTickLength="1h"/>

        </telerik:RadScheduleView.ViewDefinitions>
        <telerik:RadScheduleView.ActiveViewDefinition>
                <telerik:TimelineViewDefinition MinTimeRulerExtent="1" 
                                                MaxTimeRulerExtent="Infinity"
                                                MinorTickLength="1h" 
                                                DayStartTime="{Binding DailyStartTime, Mode=TwoWay}"
                                                DayEndTime="{Binding DailyEndTime, Mode=TwoWay}"
                                                VisibleDays="{Binding VisibleDays, Mode=TwoWay}"                                                                        
                                                StretchGroupHeaders="False"
                                                StretchAppointments="False"/>
        </telerik:RadScheduleView.ActiveViewDefinition>

        <telerik:RadScheduleView.AppointmentItemContentTemplate>
            <DataTemplate>
                <StackPanel Margin="4 2" MinHeight="20" >
                    <TextBlock Text="{Binding Subject}" FontWeight="Bold" />
                    <TextBlock Text="{Binding Appointment.Body}" TextWrapping="Wrap" />
                    <TextBlock Text="Time Range" Foreground="{StaticResource StrongBrush}"/>
                    <StackPanel Orientation="Horizontal" Margin="4 0">
                        <TextBlock Text="{Binding Path=Start, StringFormat='MMM dd, yyyy HH:MM'}"
                        FontWeight="SemiBold" Foreground="{StaticResource AccentBrush}" />
                        <TextBlock Text=" - " Foreground="{StaticResource AccentBrush}" />
                        <TextBlock Text="{Binding Path=End, StringFormat='MMM dd, yyyy HH:MM'}"
                        FontWeight="SemiBold" Foreground="{StaticResource AccentBrush}" />
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </telerik:RadScheduleView.AppointmentItemContentTemplate>

        <telerik:RadScheduleView.GroupDescriptionsSource>
            <telerik:GroupDescriptionCollection>
                <schedule:ResourceGroupDescription ResourceType="Equipment" />
            </telerik:GroupDescriptionCollection>
        </telerik:RadScheduleView.GroupDescriptionsSource>
        <telerik:RadScheduleView.GroupHeaderContentTemplate>
            <DataTemplate>
                <Border Background="{Binding Name.Brush}" Width="140" Height="{Binding GroupHeaderHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="1 1 1 0">
                    <StackPanel Margin="10 10 10 10">
                        <Image  Margin="5 0 10 0" Height="60" Width="60" Visibility="{Binding ShowPictures, Converter= {StaticResource BoolToVis}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                HorizontalAlignment="Left" Stretch="UniformToFill" Source="{Binding Name.Photo}" />
                        <TextBlock Text="{Binding FormattedName}" TextWrapping="Wrap"  Margin="8 0" VerticalAlignment="Center" />
                    </StackPanel>
                </Border>                                      
            </DataTemplate>
        </telerik:RadScheduleView.GroupHeaderContentTemplate>
        <telerik:RadScheduleView.TimeRulerItemStyleSelector>
            <local:GroupItemStyleSelector>

                <local:GroupItemStyleSelector.GroupItemStyle>
                    <Style TargetType="telerik:TimeRulerGroupItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="telerik:TimeRulerGroupItem">
                                    <Border BorderBrush="{StaticResource BasicBrush}" BorderThickness="1 1 0 0">
                                        <ContentPresenter Margin="4 2" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:GroupItemStyleSelector.GroupItemStyle>

            </local:GroupItemStyleSelector>
        </telerik:RadScheduleView.TimeRulerItemStyleSelector>
    </telerik:RadScheduleView>

我在视图模型构造函数中将 ShowPictures 初始化为 true,并将 GroupHeaderHeight 初始化为 60。调用 getter 和 setter,但视觉上没有变化。 这里的目标是启用显示图片时我在组标题模板中显示图像并增加高度,而禁用时我不显示图像并减小高度。

请,任何关于我如何改进的建议或我在此方面所犯的错误都将不胜感激。

如果有任何代码丢失,我会在询问时添加。

【问题讨论】:

  • 该问题必须与DataGrid Columns Binding 问题类似。请参阅my answer 和提供的链接。

标签: c# wpf templates telerik radscheduleview


【解决方案1】:

我猜ShowPicturesGroupHeaderHeight 属性与TimeMarkersCategories 等属性定义在同一个类中,然后您应该使用RelativeSource 来绑定它们GroupHeaderContentTemplate:

<DataTemplate>
    <Border Background="{Binding Name.Brush}" Width="140" Height="{Binding DataContext.GroupHeaderHeight, RelativeSource={RelativeSource AncestorType=telerik:RadScheduleView}}" Margin="1 1 1 0">
        <StackPanel Margin="10 10 10 10">
            <Image  Margin="5 0 10 0" Height="60" Width="60" Visibility="{Binding DataContext.ShowPictures, Converter={StaticResource BoolToVis}, RelativeSource={RelativeSource AncestorType=telerik:RadScheduleView}}" 
                                HorizontalAlignment="Left" Stretch="UniformToFill" Source="{Binding Name.Photo}" />
            <TextBlock Text="{Binding FormattedName}" TextWrapping="Wrap"  Margin="8 0" VerticalAlignment="Center" />
        </StackPanel>
    </Border>
</DataTemplate>

【讨论】:

  • 图像隐藏/显示是成功的,但是模板的高度只有在 radscheduleview 反弹到它的源时才会改变。我需要动态更改它...感谢您的回复mm8
  • 图片再次设置为可见时高度增加,图片折叠后高度不降低
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-09
  • 2013-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多