TextBlock with hidden visibility isn't reserving space - c#

I'm working on a punch clock application as a way of learning C#, XAML, and databases. Right now, my GUI isn't behaving how I would like it to.
I have a TextBlock for each of my buttons like what is shown after Start Shift.
However, when the dates are not valid, the TextBlocks are hidden. I've been able to show and hide the visibility of these how I want to. But, when I skip Start Lunch and End Lunch and go straight to End Shift, the End Shift TextBlock shows up after the Start Lunch Button as if the Start Lunch and End Lunch TextBlocks don't exist.
I've looked online and found that the visibility trait reserves space when it is hidden and doesn't reserve space when it is collapsed, but I am using hidden and it still isn't reserving space. My code is shown below.
HomeView.xaml
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!--Left column buttons-->
<StackPanel Grid.Column="0" Margin="10">
<Button Width="140" Content="Start Shift" Command="{Binding startShiftCommand}"
IsEnabled="{Binding startShiftActive}"/>
<Button Width="140" Content="Start Lunch" Command="{Binding startLunchCommand}"
IsEnabled="{Binding startLunchActive}"/>
<Button Width="140" Content="End Lunch" Command="{Binding endLunchCommand}"
IsEnabled="{Binding endLunchActive}"/>
<Button Width="140" Content="End Shift" Command="{Binding endShiftCommand}"
IsEnabled="{Binding endShiftActive}"/>
<Button Width="140" Content="Add Break" Command="{Binding addBreakCommand}"
IsEnabled="{Binding addBreakActive}"/>
</StackPanel>
<!--Right column text blocks-->
<StackPanel Grid.Column="1" Margin="10">
<TextBlock Text="{Binding day.timeIn, StringFormat=t, UpdateSourceTrigger=PropertyChanged, FallbackValue=StartTime}" FontSize="20"
Visibility="{Binding timeInValid, Converter={StaticResource BoolToVisConverter}}"
Padding="5" Margin="10"/>
<TextBlock Text="{Binding day.lunchStart, StringFormat=t, UpdateSourceTrigger=PropertyChanged, FallbackValue=LunchStart}" FontSize="20"
Visibility="{Binding lunchStartValid, Converter={StaticResource BoolToVisConverter}}"
Padding="5" Margin="10"/>
<TextBlock Text="{Binding day.lunchEnd, StringFormat=t, UpdateSourceTrigger=PropertyChanged}" FontSize="20"
Visibility="{Binding lunchEndValid, Converter={StaticResource BoolToVisConverter}, UpdateSourceTrigger=PropertyChanged}"
Padding="5" Margin="10"/>
<TextBlock Text="{Binding day.timeOut, StringFormat=t, UpdateSourceTrigger=PropertyChanged, FallbackValue=EndTime}" FontSize="20"
Visibility="{Binding timeOutValid, Converter={StaticResource BoolToVisConverter}, UpdateSourceTrigger=PropertyChanged}"
Padding="5" Margin="10"/>
</StackPanel>
</Grid>
BooleanToVisibilityConverter.cs
public class BooleanToVisiblityConverter : BaseValueConverter<BooleanToVisiblityConverter>
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter == null)
return (bool)value ? Visibility.Hidden : Visibility.Visible;
else
return (bool)value ? Visibility.Visible : Visibility.Hidden;
}
}
HomeViewModel.cs
private void startShift()
{
day.date = DateTime.Now;
dateValid = true;
day.timeIn = DateTime.Now;
timeInValid = true;
day.breaks = new ObservableCollection<Break>();
RaisePropertyChanged("day"); //A simple fix to update the UI
process(Command.startShift);
infoText = string.Format("Shift started at {0:t}", day.timeIn);
writeToFile();
}
private void startLunch()
{
day.lunchStart = DateTime.Now;
lunchStartValid = true;
RaisePropertyChanged("day");
process(Command.startLunch);
infoText = string.Format("Lunch started at {0:t}", day.lunchStart);
writeToFile();
}
private void endLunch()
{
day.lunchEnd= DateTime.Now;
lunchEndValid = true;
RaisePropertyChanged("day");
process(Command.endLunch);
infoText = string.Format("Lunch ended at {0:t}", day.lunchEnd);
writeToFile();
}
private void endShift()
{
day.timeOut = DateTime.Now;
timeOutValid = true;
RaisePropertyChanged("day");
calcTotalTime();
process(Command.endShift);
infoText = string.Format("Shift ended at {0:t}\nTotal time for {1:d} is {2}", day.timeOut, day.date, day.totalTime);
//Save to database
WorkHoursDBContext context = new WorkHoursDBContext();
context.Days.Add(day);
context.SaveChanges();
writeToFile();
}
The method process() is responsible for changing the boolean of each button to decide if it is enabled or not.
Is there any way I can prevent my End Shift TextBlock from sliding up when the Start Lunch and End Lunch TextBlocks are hidden?

Related

UWP C# - listview change "item" background color depending of value (not the entire row)

The following code run when loading rows to listview what happens only once.
My ListView items only have 2 values - "x" and "n". I want the item("cell") with value "x" to have as background color Red.
The following code has 2 issues for me:
1) I do not want to specify all columns/items (goodFH, Position, etc) to have the "cell" Red if value = "x" (would like as pseudocode "if current cell value = "x" then Red")
2) args.ItemContainer.Background change the entire row background and not the "cell" I wish!
private void listViewContentChange(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (((Binding.Car)args.Item).GoodFH == "x")
{
args.ItemContainer.Background = (SolidColorBrush)Application.Current.Resources["Red"];
}
else
{
if (((Binding.Car)args.Item).Position == "x")
{
args.ItemContainer.Background =(SolidColorBrush)Application.Current.Resources["red"];
}
}
}
<DataTemplate x:DataType="data:Car">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" Margin="20,20,0,0">
<TextBlock FontSize="18" Text="{x:Bind GoodFH}" HorizontalAlignment="Right" Height="20" Width="158"></TextBlock>
<TextBlock FontSize="18" Text="{x:Bind Position }" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
<TextBlock FontSize="18" Text="{x:Bind PathFHfs}" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
<TextBlock FontSize="18" Text="{x:Bind PathBHFlSp }" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
Any Help? Hope the question is understandable!
As far as I known, we can not change the Background of the cell by setting the ItemContainer.Background.
We should be able to set the TextBlock in the Grid that we can change the Background of the Grid.
Also we can use the bind to set the Background of the Grid. To bind the "GoodFH" to the Background, we should be able to use the IValueConverter.
For example:
The MyValueConverters.cs code:
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value.ToString() == "x")
{
return new SolidColorBrush(Colors.Red);
}
return new SolidColorBrush(Colors.Transparent);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value;
}
The XAML code:
<Page.Resources>
<local:MyValueConverters x:Key="MyConverter" />
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView Name="MyListView" ItemsSource="{x:Bind Cars}" ContainerContentChanging="listViewContentChange">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Car">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Margin="20,20,0,0">
<Grid Background="{x:Bind GoodFH,Converter={StaticResource MyConverter}}">
<TextBlock FontSize="18" Text="{x:Bind GoodFH}" HorizontalAlignment="Right" Height="20" Width="158"></TextBlock>
</Grid>
<Grid Background="{x:Bind Position,Converter={StaticResource MyConverter}}">
<TextBlock FontSize="18" Text="{x:Bind Position }" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
</Grid>
<TextBlock FontSize="18" Text="{x:Bind PathFHfs}" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
<TextBlock FontSize="18" Text="{x:Bind PathBHFlSp }" HorizontalAlignment="Right" Height="20" Width="78"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>

Xaml - Bind listviewitem source object

I use an observableCollecion in my VM. This Collection is bind into my view in a ListView. In my items I try to get the element who create this item. Add it in my commandParameter and do the thing.
Here's my VM :
public RelayCommand<SelectionCommandParameter> CmdRemoveFromQuiz { get; set; }
public ObservableCollection<Question> SelectedQuiz
{
get { return _selectedQuiz; }
set
{
_selectedQuiz = value;
RaisePropertyChanged("SelectedQuiz");
}
}
private void RemoveFromQuiz(SelectionCommandParameter selection)
{
if (selection.Parameter is Question)
{
ObservableCollection<Question> tempQuiz = SelectedQuiz;
Question _question = (Question)selection.Parameter;
tempQuiz.Remove(_question);
SelectedQuiz = tempQuiz;
}
}
The problem start with the RemoveBtn I start the command, and selection stay null I want to get the ObservableCollection<Question> object use in my ListViewitem
Now My View :
<userControls:CharmFlyout
x:Name="cfoQuizList"
x:Uid="QuizListCreatingPageFlyout"
Heading="Question Multiple"
HorizontalAlignment="Left"
Grid.Column="0"
Grid.RowSpan="2"
Style="{StaticResource stlAddRecipientFlyout}">
<tut:TutorialAwareListView x:Name="gvQuizItem"
ItemsSource="{Binding SelectedQuiz}"
IsItemClickEnabled="True"
CanReorderItems="True"
SelectionMode="None"
ManipulationMode="TranslateRailsX">
<ListView.ItemTemplate>
<DataTemplate x:Name="DTQuizItem">
<Grid HorizontalAlignment="Left" Width="{StaticResource RectangleTileWidth}" Height="{StaticResource RectangleTileHeight}"
Margin="0 0 0 0" Background="{StaticResource OrangeBackgroundThemeBrush}">
<Grid Grid.Column="1">
<Button x:Name="RemoveBtn" Content="X" HorizontalAlignment="Right" VerticalAlignment="Top" Width="40" Height="40"
BorderThickness="0" Command="{Binding DataContext.CmdRemoveFromQuiz, ElementName=gvQuizItem}" CommandParameter="{Binding Question}"/>
<maxCtrls:MaxAutoScrollingContentPresenter VerticalAlignment="Center"
ScrollingDuration="{Binding Name, Converter={StaticResource TextToTimeToReadShortFormatConverter}}"
ScrollingBeginTime="0:0:2">
<TextBlock Text="{Binding Name}" FontWeight="SemiBold"
Foreground="{StaticResource WhiteBackground}"
Margin="20,5,10,5" VerticalAlignment="Center" TextWrapping="Wrap"/>
</maxCtrls:MaxAutoScrollingContentPresenter>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</tut:TutorialAwareListView>
</userControls:CharmFlyout>
The TutorialAwareListView Work exactly like a ListView. I use it juste to point the element while the tutorial is running.
It's a Windows Store App !! I can't do all the thing we would like to.
You should change your SelectionMode="None" to Single or Multiply.
And make new ObservableCollection for selected items. You bind just ItemsSource="{Binding SelectedQuiz}". Bind SelectedItems="{...}"

Windows Phone 7 - Toggle switch in list box

In a group of toggle switches I couldn't control the any toggle switch individually, rather if I try to change one then all the values change simultaneously.
My Xaml:-
<ListBox HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="0,0,0,0" Name="yourChoiceListBox" VerticalAlignment="Top" Width="476" ItemsSource="{Binding yourChoiceList, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" BorderThickness="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Width="476" Height="60">
<TextBlock Margin="10,0,0,0" FontSize="24" FontWeight="SemiBold" Foreground="Black" Width="250" Text="{Binding title}" VerticalAlignment="Center" Height="35" TextTrimming="WordEllipsis" />
<TextBlock FontSize="24" FontWeight="SemiBold" Foreground="Black" Width="150" Text="{Binding valueDesc}" HorizontalAlignment="Right" FlowDirection="RightToLeft" VerticalAlignment="Center" Visibility="{Binding valueVisible}" />
<toolkit:ToggleSwitch x:Name="toggle" Foreground="Black" Content="{Binding toggleContent}" IsChecked="{Binding DataContext.isCheck,ElementName=yourChoiceListBox,Mode=TwoWay}" Height="110" Width="198" HorizontalAlignment="Right" Margin="40,-15,0,0" Visibility="{Binding tongleVisible}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My ViewModel CS:-
public static string _toggleContent;
public string toggleContent
{
get { return _toggleContent; }
set { this.RaiseAndSetIfChanged(x => x.toggleContent, value); }
}
public static bool _isCheck;
public bool isCheck
{
get { return _isCheck; }
set
{
this.RaiseAndSetIfChanged(x => x.isCheck, value);
if (isCheck)
toggleContent = "Yes";
else
toggleContent = "No";
}
}
Here i want to change the toggle switch content in to "Yes" or "No". If i choose 'On' the content should be "Yes". But here if i select one toggle switch all the toggle switch is changed. Please let me any idea to solve my problem. Thanks in advance.
This is your ToggleSwitch:
<toolkit:ToggleSwitch x:Name="toggle" Foreground="Black" Content="{Binding toggleContent}"
IsChecked="{Binding DataContext.isCheck,ElementName=yourChoiceListBox,Mode=TwoWay}"
Height="110" Width="198" HorizontalAlignment="Right" Margin="40,-15,0,0"
Visibility="{Binding tongleVisible}" />
the problem is here:
IsChecked="{Binding DataContext.isCheck,ElementName=yourChoiceListBox,Mode=TwoWay}"
You are binding the IsChecked property of the ToggleSwitch to the isCheck property of your list.
You should bind the IsChecked property of the ToggleSwitch to the isCheck property of your list item like this:
IsChecked="{Binding isCheck, Mode=TwoWay}"

How to update ListBoxItem property

I want to update DownloadingSpeed Property which is binded to TextBox in a ListBoxItem. I am generating ListBoxItems in c#. Please guide me how do i update Binding Content of TextBoxes within a ListItemBox in C#.
WPF LisBox Code
<ListBox Width="Auto"
Name="WebsiteList"
MouseUp="SelectedListItem"
SelectedIndex="0"
Grid.Column="1"
Grid.Row="2"
Grid.RowSpan="2"
Margin="0,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="920">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Grid Width="920">
<TextBlock FontWeight="Bold" FontSize="18" Width="Auto">
<Hyperlink NavigateUri="http://google.com" FontStyle="Italic">
<Label Content="{Binding WebsiteTitle}" /><Label FontSize="10" Margin="0,0,0,3" Content="{Binding DirectorySize}" />
</Hyperlink>
</TextBlock>
<TextBlock Width="0" TextAlignment="right">
<TextBlock Visibility="Hidden" Text="{Binding DownloadID}"/>
<TextBlock Visibility="Hidden" Text="{Binding DirectoryPath}"/>
<TextBlock Visibility="Hidden" Text="{Binding CurrentTime}"/>
<TextBlock Visibility="Hidden" Text="{Binding CurrentDate}"/>
<TextBlock Visibility="Hidden" Text="{Binding GivenUrl}"/>
</TextBlock>
</Grid>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Grid Width="920">
<ProgressBar Name="progress1" Maximum="100" Minimum="0" Value="30" Background="#FFF" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=Width}" Height="10" />
</Grid>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Grid Width="920">
<TextBlock HorizontalAlignment="Left" Width="Auto">Status: <TextBlock Text="{Binding Status}"/></TextBlock>
<TextBlock Width="Auto" TextAlignment="right">
<TextBlock Text="Downloading Speed: "/>
<TextBlock Name="DownloadingSpeed" Text="{Binding DownloadingSpeed}"/>
</TextBlock>
</Grid>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In MainWindow.xaml.cs
private void GenerateList()
{
List<Download> WebsitesList = new List<Download>();
WebsitesList.Add(new Download() {DownloadID = ID, WebsiteTitle = WebTitle, Status = WebStatus, CurrentTime = CurrentTime,CurrentDate = CurrentDate, DownloadingSpeed = DownloadSpeed, DirectoryPath = path, DirectorySize = helper.GetDirectorySize(path),GivenUrl = url });
WebsiteList.ItemsSource = WebsitesList;
}
//get download speed and update DownloadingSpeed
private void updateDownloadingSpeed(object sender, EventArgs e)
{
interfaceStats = NetworkInterface.GetAllNetworkInterfaces()[0].GetIPv4Statistics();
downloadspeed = (interfaceStats.BytesReceived - previousbytesreceived) / 1024;
previousbytesreceived = NetworkInterface.GetAllNetworkInterfaces()[0].GetIPv4Statistics().BytesReceived;
Download.DownloadingSpeed = Math.Round(downloadspeed, 2) + " KB/s"; //Rounding to 2 decimal places and save in DownloadSpeed Property
}
In Download.cs
public class Download : INotifyPropertyChanged
{
private string _DownloadingSpeed = "0 kb/s";
public string DownloadingSpeed
{
get { return _DownloadingSpeed; }
set
{
if (_DownloadingSpeed == value)
return;
_DownloadingSpeed = value;
this.OnPropertyChanged("DownloadingSpeed");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Add UpdateSourceTrigger for TextBlock.
<TextBlock Name="DownloadingSpeed" Text="{Binding DownloadingSpeed, UpdateSourceTrigger=PropertyChanged}"/>
You might find that your code works if you use WPF properly by defining properties and declaring XAML correctly. It is customary to have an ObservableCollection<T> property that you data bind to the UI collection control. You would then data bind it to the ItemsSource property of the control:
<ListBox ItemsSource="{Binding Items}" ... />
Then, when you want to update any properties of the items, you need to set the properties of the items. This:
Download.DownloadingSpeed = Math.Round(downloadspeed, 2) + " KB/s";
... is not setting the property of an item from the collection. To do that, you'd need to do something like this:
// Use whatever filter you want to find the correct item from the collection
Download downloadInstance = Items.Where(d => d.Name == "SomeName").First();
downloadInstance.DownloadingSpeed = Math.Round(downloadspeed, 2) + " KB/s";

Switch from one DataTemplate to other

In my wpf application, there is View class where I've ListBox. I wrote the code for double click event of ListBox Item.so when I double click on any list Box Item that item will be posted in my Harvest account.Here is the event:
private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Submit clicked Entry
try
{
ListBoxItem item = (ListBoxItem)sender;
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)item.DataContext;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project" && entryToPost.ClientNameBinding == "Select Client")
MessageBox.Show("Please select you Project and Client");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
MessageBox.Show("Entry posted");
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
catch (Exception)
{ }
}
My xaml code:
<DataTemplate x:Key="DefaultDataTemplate">
<StackPanel Orientation="Horizontal" Width="596">
<TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/>
<TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
<TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
<TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
<TextBox Text="{Binding ProjectNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
<TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="71"/>
</StackPanel>
</DataTemplate>
<!-- Editable DataTemplate -->
<DataTemplate x:Key="EditableDataTemplate">
<StackPanel Orientation="Horizontal" Width="596">
<ComboBox x:Name="ClientComboBox" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=clientList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ClientNameBindingClass, Mode=OneWayToSource}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="145"/>
<TextBox Text="{Binding ApplicationNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
<TextBox Text="{Binding StartTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
<TextBox Text="{Binding StopTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
<TextBox Text="{Binding TaskNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
<ComboBox x:Name="ProjectComboBox" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=projectList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ProjectNameBindingClass, Mode=OneWayToSource}" Width="71" Background="Yellow" BorderThickness="0"/>
</StackPanel>
</DataTemplate>
<!-- DataTemplate Selector -->
<l:DayViewListDataTemplateSelector x:Key="templateSelector"
DefaultDataTemplate="{StaticResource DefaultDataTemplate}"
EditableDataTemplate="{StaticResource EditableDataTemplate}"/>
I've timer in my class which generates that EditableDataTemplate with two comboBoxes. My problem is, when I select Client and Project in ComboBoxes and double click on the entry, it's posted in my account but at that time I want it to convert from editableDataTemplate to DefaultDataTemplate (i.e those two comboboxes should become textboxes likewise in DefaultDataTemplate). How should I achieve this result?
I don't think the DataTemplateSelector offers a method of changing the data template on request, it is merely used to choose different templates for different types of data (not data states).
I think probably the best way would be to add a property, lets call it IsInEditMode, to your data model. You could then add both the TextBlock and the Combobox to your data template and toggle their visibility according to the value of IsInEditMode.
By the way: if you use the ListBox.SelectedItem property in your DoubleClick-eventhandler you can directly access the data model element without having to first get the ListBoxItem and then access
its data context.
private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Submit clicked Entry
try
{
if(listBox1.SelectedItem is Harvest_TimeSheetEntry)
{
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)listBox1.SelectedItem;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project" && entryToPost.ClientNameBinding == "Select Client")
MessageBox.Show("Please select you Project and Client");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
MessageBox.Show("Entry posted");
entryToPost.IsInEditMode = true; //set edit mode!
}
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
catch (Exception)
{ }
}

Categories

Resources