ListBox WPF Hierarchy

I have a Listbox associated with an observable collection, and the XAML snippet shows what each item (text blocks and Slidercontrol) will contain. Slidercontrol is set to mostly invisible

         ListBox.ItemTemplate>
             <DataTemplate>
               <StackPanel Orientation="Vertical" Width="500">

                 <stackPanel Orientation="Horizontal">
                   <TextBlock Margin="0,0,0,0"  Width="100"........
                   <TextBlock Margin="200,10,0,0" Width="100"........ 
                 </StackPanel>

                <Slider Margin="0,0,0,0" Height="100".................

                 <StackPanel Orientation="Horizontal">
                   <TextBlock Width="100" TextWrapping="Wrap"..............
                   <TextBlock Width="100" TextWrapping="Wrap"...............
                 </StackPanel>                                
              </StackPanel>
            </DataTemplate>
         </ListBox.ItemTemplate>

I want to first check the listableCollection object for a specific Time property, if the time is in the current system time, I want to activate the corresponding ListBox control of the slider control and update it, the toner indicates progress in time and is updated until the end of time and the user cannot move it but how can I access or iterate through the ListBoxitem to then activate the slider control via visualhelptree.HELP !!!!!!

+3
source share
2


, Slider , ProgressBar ( Slider , ). , , TreeVisualHelper. , ObservableCollection:

ObservableCOllection<MyObject> Collection;

MyObject double, ProgressBar, , Timer, 5 , , , , , :

public class MyObject
{
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }

    public double ProgressValue { get; set; }
    private System.Timers.Timer TimeChecker;

    public MyObject()
    {
         // 5 Minutes = 5 * 60 Seconds = 5 * 60 * 1000 Milliseconds
         TimeChecker = new Timer(300000);
         TimeChecker.Elapsed += CheckTimes;
    }


    public CheckTimes()
    {
         // Check StartTime and EndTime to decide whether to enable the slider or not.
         if(...)
         {
              // Here you can add the appropriate value to indicate the current progress
              ProgressValue == ....;
         }
         else
              ProgressValue == ....;
    }
}

ProgressBar.Value ProgressValue, :

<BrogressBar Value="{Binding ProgressValue}"/>

, . - , 5 , .

+2

ValueConverter - - :

<Slider Margin="0,0,0,0" Height="100" IsEnabled="{Binding Path=Time, Converter={StaticResource IsTimeNearSystemTimeConverter}}" />

,

public class BetweenTimesMultiValueConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        var time1 = (DateTime)values[0];
        var time2 = (DateTime)values[1];
        var current = DateTime.Now;
        return time1 > current && time2 < current;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

xaml, :

<Slider Margin="0,0,0,0" Height="100">
    <Slider.IsEnabled>
        <MultiBinding Converter="{StaticResource betweenTimeConverter}">
            <Binding Path="EarlyTime" />
            <Binding Path="LateTime" />
        </MultiBinding>
    </Slider.IsEnabled>
</Slider>
+1

All Articles