I have a Listbox bound to an observable collection and XAML snippet shows what each item will contain (textblocks and Slidercontrol ) Slidercontrol is set to invisible intially
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 observableCollection list object for certain Time property , if the time is inside the current system time , i want to Activate corresponding slider control ListBox Item and update it the silder indicates progress in time and updated until end time and user cannot move it , but How to i access or iterate ListBoxitem so that i can then activate the Slider control via visualhelptree.HELP!!!!!!
Updated Again
First off all, as long as your are just using the Slider to shoe just the progress in time, then the right control to use is the ProgressBar control (The Slider control is used to let user change a value, for example changing the volum of a media player). Moreover, you can implement this more easily, without the use of the TreeVisualHelper. Lets say that your are binding to the following ObservableCollection object:
ObservableCOllection<MyObject> Collection;
Edit MyObject class and add double property to indicate the progress value for the ProgressBar, more over add a Timer object to fire every 5 minutes to check the two times and decides whether to enable the Slider or not by changing the boolean value, sothing like the follwoing:
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 == ....;
}
}
Then, in the item template, bind your ProgressBar.Value property to the ProgressValue property, it will be something similar to the following:
<BrogressBar Value="{Binding ProgressValue}"/>
This way each item will have its own timer. A better alternative to have just one timer that iterate through the collection each 5 minutes and do what is necessary.
Try a ValueConverter - you need something like this:
<Slider Margin="0,0,0,0" Height="100" IsEnabled="{Binding Path=Time, Converter={StaticResource IsTimeNearSystemTimeConverter}}" />
EDIT
sounds like youll need to do multibinding with a multivalueconverter
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();
}
}
add the above class as a static resource in you xaml, then use it like this:
<Slider Margin="0,0,0,0" Height="100">
<Slider.IsEnabled>
<MultiBinding Converter="{StaticResource betweenTimeConverter}">
<Binding Path="EarlyTime" />
<Binding Path="LateTime" />
</MultiBinding>
</Slider.IsEnabled>
</Slider>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With