Calendar Programming: How can I place, create and size items that represent a task using MVVM?

StackOverflow https://stackoverflow.com/questions/21681690

  •  09-10-2022
  •  | 
  •  

Question

I just have a conceptual question here. First of all I am programming a Windows 8.1 App using C# and XAML as well as the MVVM-Light Toolkit.
I am working on a Schedule at the moment which is backed by a calendar. The calendar should have a "DayView" which consists of a timeline on the left that goes from top to bottom. Now on the right of that timeline I want to show something similar to a rectangle as a visualization for a given task with a height that represents its duration. Every task has a starting time so the top of that rectangle should be placed next to the corresponding entry in the timeline.

Well I hope it is clear what I am trying to say here basically that should look similar to the Calendar-App coming with Windows 8. I will post a screenshot of that below that post.

Now I have tried or thought of multiple things by now that lead to more or less complicated problems. The best approach I had was creating a List a placing it on the right of that timeline. Now that List would contain a huge amount of items (maybe one for each pixel) which will be changed in size. The size then is 0 or in relation to the duration of the task depending on whether there is a one or not.

But that leads to huge problems when it comes to changing an entry or having more than one task for the same time since those items wont overlap. And I don't want to place more than one or two of those per page since the performance-issue would be overkill...

One of the issues I have is that I am using the MVVM-Concept and don't know how to be able to create new UI-Elements such as a rectangle without touching the code-behind. That is why basically the only thing I have thought about by now were lists...

I hope it is clear what I meant.

Thank you very much for your help!

FunkyPeanut

enter image description here

Was it helpful?

Solution

Problem solved using a Grid as the ItemsPanel of an ItemsControl:

<ItemsControl Grid.Column="2" ItemsSource="{Binding Day.ItemsList, Source={StaticResource Locator}}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid Width="20"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid Height="{Binding Height}" Width="20" Margin="{Binding Margin}">
                <Grid.Background>
                    <SolidColorBrush Opacity="{Binding Opacity}" Color="{Binding ColorHash, Converter={StaticResource HexToColorConverter}}"/>
                </Grid.Background>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>  

With the following Data:

ItemsList = new ObservableCollection<object>(tmpPeriodsList.Select((x, i) => new
    {
        ColorHash = x.ColorHash,
        Index = i,
        Margin = StartPosition(i),
        Opacity = 0.6,
        Height = 45,
    }));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top