项目未在xceed timelinePanel控件中显示 [英] item not showing in xceed timelinePanel control

查看:64
本文介绍了项目未在xceed timelinePanel控件中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试使用TimelinePanel控件和一个项目集合,我遇到麻烦使它工作(没有任何显示)。我正在尝试两种不同的方法。



XAML:



 < span class =code-keyword><  网格 >  
< Grid.RowDefinitions >
< RowDefinition 高度 = 1 * / >
< RowDefinition 高度 = 1 * / >
< / Grid.RowDefinitions >
< 网格 Grid.Row = 0 >
< ItemsControl ItemsSource = {绑定列表,来源= {StaticResource viewModel}} >
< ItemsControl.Template >
< ControlTemplate < span class =code-attribute> TargetType = ItemsControl >
< xtc:TimelinePanel BeginDate = {Binding startHour,Source = {StaticResource viewModel}} EndDate = {Binding endHour,Source = {StaticResource viewModel}} 背景 = Aqua / >
< / ControlTemplate >
< / ItemsControl.Template >
< ItemsControl。 ItemTemplate >
< DataTemplate >
< 边框 背景 = 蓝色 宽度 = 100 高度 = 25 保证金 = 0,2,0,2 xtc:TimelinePanel.Date = {Binding start} >
< TextBlock 文字 = {Binding name} < span class =code-attribute> / >
< / Border >
< / DataTemplate >
< / ItemsControl.ItemTemplate >
< / ItemsControl >
< / Grid >
< 网格 Grid.Row = 1 >
< xtc:TimelinePanel 背景 = LightBlue BeginDate = < span class =code-keyword> {Binding startHour,Source = {StaticResource viewModel}} EndDate = {Binding endHour,Source = {StaticResource viewModel}} >
< ItemsControl ItemsSource = {Binding list,Source = {StaticResource viewModel}} >
< ItemsControl.ItemTemplate >
< DataTemplate >
< Border 背景 = 蓝色 宽度 = 100 高度 = 25 保证金 = 0,2,0 ,2 xtc:TimelinePanel.Date = {Binding start} xtc :TimelinePanel.DateEnd = {Binding end} >
< TextBlock 文字 = {绑定名称} / >
< / Border >
< / DataTemplate >
< /ItemsControl.ItemTemplate >
< / ItemsControl >
< / xtc:TimelinePanel >
< / Grid >
< / Grid >





和后面的代码:



  public   partial   class  MainWindow:Window 

{
public MainWindow()
{
InitializeComponent();
}
}

public class timeViewModel
{
public DateTime startHour
{
get ; set ;
}

public DateTime endHour
{
get ; set ;
}

public ObservableCollection& lt; timelineItem& gt; list { get ; set ; }

public timeViewModel()
{
startHour = DateTime.Now.Date;
endHour =(DateTime.Now.Date + TimeSpan.FromDays( 22 ));
getData();
}

private void getData()
{
List& lt; timelineItem& gt; listItem = new List& lt; timelineItem& gt;();
for int i = 6 ; i& lt; 20 ; i ++)
{
timelineItem newItem = new timelineItem();
newItem.name =& quot; test& quot; + i.ToString();
newItem.start =(DateTime.Now.Date + TimeSpan.FromDays(i));
newItem.end =(DateTime.Now.Date + TimeSpan.FromDays(i + 2 ));
listItem.Add(newItem);
}
list = new ObservableCollection& lt; timelineItem& gt;(listItem);
}
}
}

public class timelineItem
{
public string name {获得; set ; }
public DateTime start { get ; set ; }
public DateTime end { get ; set ; }
}





关于如何在时间线面板上展示项目的任何帮助都很棒。



谢谢



Pierre

解决方案

收到Xceed的解决方案:





我不会使用ItemsControl.Template和ItemsControl.ItemTemplate,而是使用:

- ItemsControl.ItemsPanel定义要使用的面板:TimelinePanel,

- ItemsControl.ItemTemplate定义每个项目的视觉效果,

- ItemsControl.ItemContainerStyle定义附加属性Date和DateEnd。这是必要的,因为ItemsControls将自动为每个项创建ContentPresenter,其内容为ItemsControl.ItemTemplate中定义的Border。为了正常工作,TimelinePanel需要在其项目的顶层找到附加属性Date和DateEnd,所以在ContentPresenters上。



类似于:



 <  网格 >  
< itemscontrol x:name = _ itemsControl xmlns:x = #unknown >
ItemsSource ={Binding list,Source = {StaticResource viewModel}}>
< itemscontrol.itemspanel >
< itemspaneltemplate >
< xtc:timelinepanel begindate = {Binding startHour, Source = {StaticResource viewModel}} xmlns:xtc = #unknown >
EndDate ={绑定endHour,Source = {StaticResource viewModel}}
Background =Aqua/& GT;
< / xtc:timelinepanel > < / itemspaneltemplate >
< / itemscontrol.itemspanel >
< itemscontrol.itemtemplate >
< datatemplate >
< border 背景 = Blue >
Height =25
Margin =0,2,0,2> ;
< textblock < span class =code-attribute> text = {Binding name} < span class =code-keyword>>
Foreground =White/>
< / textblock > < / border >
< / datatemplate >
< / itemscontrol.itemtemplate >
< itemscontrol.itemcontainerstyle >
< style >
< setter property = xtc:TimelinePanel.Date >
Value ={Binding Path = start}/>
< setter < span class =code-attribute> property = xtc:TimelinePanel.DateEnd >
Value ={Binding Path = end}/>
< / setter > < / setter > < / style >
< / itemscontrol.itemcontainerstyle >
< / itemscontrol >
< / grid >


Hi
I am trying to use the TimelinePanel control with a collection of item and I am having troubles making it work (nothing is showing). I am trying 2 different approach.

XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <ItemsControl ItemsSource="{Binding list, Source={StaticResource viewModel}}">
            <ItemsControl.Template>
                <ControlTemplate TargetType="ItemsControl">
                    <xtc:TimelinePanel BeginDate="{Binding startHour, Source={StaticResource viewModel}}" EndDate="{Binding endHour, Source={StaticResource viewModel}}" Background="Aqua" />
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Background="Blue" Width="100" Height="25" Margin="0, 2, 0, 2" xtc:TimelinePanel.Date="{Binding start}">
                        <TextBlock Text="{Binding name}" />
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
    <Grid Grid.Row="1">
        <xtc:TimelinePanel Background="LightBlue" BeginDate="{Binding startHour, Source={StaticResource viewModel}}" EndDate="{Binding endHour, Source={StaticResource viewModel}}">
            <ItemsControl ItemsSource="{Binding list, Source={StaticResource viewModel}}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border Background="Blue" Width="100" Height="25" Margin="0, 2, 0, 2" xtc:TimelinePanel.Date="{Binding start}" xtc:TimelinePanel.DateEnd="{Binding end}">
                            <TextBlock Text="{Binding name}" />
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </xtc:TimelinePanel>
    </Grid>
</Grid>



and the code behind:

public partial class MainWindow : Window

    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
 
    public class timeViewModel
    {
        public DateTime startHour
        {
            get; set;
        }
 
        public DateTime endHour
        {
            get; set;
        }
 
        public ObservableCollection&lt;timelineItem&gt; list { get; set; }
 
        public timeViewModel()
        {
            startHour = DateTime.Now.Date;
            endHour = (DateTime.Now.Date + TimeSpan.FromDays(22));
            getData();
        }
 
        private void getData()
        {
            List&lt;timelineItem&gt; listItem = new List&lt;timelineItem&gt;();
            for (int i = 6; i &lt; 20; i++)
            {
                timelineItem newItem = new timelineItem();
                newItem.name = &quot;test &quot; + i.ToString();
                newItem.start = (DateTime.Now.Date + TimeSpan.FromDays(i));
                newItem.end = (DateTime.Now.Date + TimeSpan.FromDays(i + 2));
                listItem.Add(newItem);
            }
            list = new ObservableCollection&lt;timelineItem&gt;(listItem);
        }
    }
}
 
public class timelineItem
{
    public string name { get; set; }
    public DateTime start { get; set; }
    public DateTime end { get; set; }
}



Any help on how the show the item on the timelinepanel would be great.

Thanks

Pierre

解决方案

Received solution from Xceed:
Hi,

I would not use "ItemsControl.Template" and "ItemsControl.ItemTemplate", but instead use :
-"ItemsControl.ItemsPanel" to define the panel to use : TimelinePanel,
-"ItemsControl.ItemTemplate" to define the visual of each item,
-"ItemsControl.ItemContainerStyle" to define the attached property "Date" and "DateEnd". This is necessary since the ItemsControls will automatically create ContentPresenter for each items with the content being the "Border" defined in ItemsControl.ItemTemplate. To work correctly, the TimelinePanel needs to find the attached property "Date" and "DateEnd" at top level on its items, so on the ContentPresenters.

Something like :

<grid>
        <itemscontrol x:name="_itemsControl" xmlns:x="#unknown">
                      ItemsSource="{Binding list, Source={StaticResource viewModel}}">
            <itemscontrol.itemspanel>
              <itemspaneltemplate>
                  <xtc:timelinepanel begindate="{Binding startHour, Source={StaticResource viewModel}}" xmlns:xtc="#unknown">
                                    EndDate="{Binding endHour, Source={StaticResource viewModel}}"
                                    Background="Aqua"/>
              </xtc:timelinepanel></itemspaneltemplate>
            </itemscontrol.itemspanel>
            <itemscontrol.itemtemplate>
              <datatemplate>
                  <border background="Blue">
                          Height="25"
                          Margin="0, 2, 0, 2">
                    <textblock text="{Binding name}">
                                Foreground="White"/>
                  </textblock></border>
              </datatemplate>
            </itemscontrol.itemtemplate>
            <itemscontrol.itemcontainerstyle>
              <style>
                  <setter property="xtc:TimelinePanel.Date">
                          Value="{Binding Path=start}"/>
                  <setter property="xtc:TimelinePanel.DateEnd">
                          Value="{Binding Path=end}" />
              </setter></setter></style>
            </itemscontrol.itemcontainerstyle>
        </itemscontrol>
      </grid>


这篇关于项目未在xceed timelinePanel控件中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆