|
You start by examining how your mail is received, where it is stored, and what events are associated with it. At the very least, the contents of a given folder (or database) will be updated which can be monitored by a File Watcher (or other "monitor") class instance.
Get your "link" to save something if you can't figure the rest out.
|
|
|
|
|
I have a class that derives from Window and I use it for ALL windows in my application. I have a resource dictionary for themes contained in App.xaml, which looks like this:
<Application [...]>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="ThemeDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/MyTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
[...]
</Application>
The style for my derived window type is located in an external assembly and declared using Generic/Themes.xaml pattern.
For switching the theme, I remove the existing theme dictionary and replace it with the new one. Oddly, the changes in styles only reflect in MainWindow and not in any additionally created windows.
My derived window type is styled like this:
<ControlTemplate x:Key="WindowTemplate" TargetType="{x:Type Controls:CustomWindow}">
[...]
</ControlTemplate>
<Style x:Key="{x:Type Controls:CustomWindow}" TargetType="{x:Type Controls:CustomWindow}" BasedOn="{StaticResource CustomWindowStyle}">
[...]
</Style>
Note, the theme specified at design-time always works in ALL windows; however, any themes specified at run-time only apply to MainWindow and never additional windows.
Any idea why this is?
|
|
|
|
|
Have you tried calling BeginInit and EndInit on the main resource dictionary?
ResourceDictionary toRemove = ...;
ResourceDictionary toAdd = ...;
Resources.BeginInit();
try
{
if (toRemove != null)
{
Resources.MergedDictionaries.Remove(toRemove);
}
if (toAdd != null)
{
Resources.MergedDictionaries.Add(toAdd);
}
}
finally
{
Resources.EndInit();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I applied your suggestion and the method that sets the dictionary is now as follows:
public Result Set(string Path)
{
Result Result = null;
ResourceDictionary NewDictionary = this.Get(Path);
this.Dictionary.BeginInit();
try
{
if (this.Dictionary != null && NewDictionary != null)
{
this.Dictionary.Clear();
this.Dictionary.MergedDictionaries.Add(NewDictionary);
Result = new Success();
}
}
catch (Exception e)
{
Result = new Error(e.Message);
}
finally
{
this.Dictionary.EndInit();
}
return Result;
}
Where NewDictionary is a resource dictionary read from a file and this.Dictionary is the resource dictionary containing the merged dictionaries.
Unfortunately, this doesn't change anything.
|
|
|
|
|
I just found this in our app's CTOR:
System.Windows.FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
MSDN Says [^]
Gets or sets a value that indicates whether a data-bound TextBox should display a string that is identical to the value of the source its Text property
As is typical with MSDN, this explanation says nothing of value.
Why wouldn't a textbox display what's in its Text property by default?
Anyone ever used this? Can you shed some light on what this really means?
If it's not broken, fix it until it is
|
|
|
|
|
I've never used it but it looks like it is referring not to the Text property of the TextBox, but to the source that is data bound to the Text property.
From looking at the code it appears it has to do with an edge case where the TextBox is pushing a change back to the binding source but may not notice if the binding source has modified that string.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Just found this[^]
Seems like a good explanation, although this property seems to be because of a bug.
If it's not broken, fix it until it is
|
|
|
|
|
I have tried a lot of things without luck. What I'm trying to do is create a XAML TabControl that keeps all of the first five visible TabItems on the first row when the last two hidden TabItems become visible. What I want is for the two last TabItems to wrap when they become visible but keep the first five on the first row. I have tried to use a TextBlock with a LineBreak but when the last two TabItems become visible the fifth TabItem wraps with the new visible last two TabItems. Any help would be great.
|
|
|
|
|
The answer to my problem had to do with setting the widths of the collapsed tabs once they were changed to visible. What I did was give the newly visible tabs the correct width and they pushed the other tabs to the first row.
|
|
|
|
|
This is a very simple example, and I can't get it to work
My UserControl
<Grid>
<Border>
<TextBlock Text="{Binding DayNameCaption}"
Background="Green"
Foreground="White"
Height="25"
Width="75"/>
</Border>
</Grid>
Code Behind
public partial class MonthViewDayColumnHeader : UserControl
{
#region DP DayName
public static readonly DependencyProperty DayNameCaptionProperty =
DependencyProperty.Register("DayNameCaption",
typeof(string),
typeof(MonthViewDayColumnHeader),
new PropertyMetadata("Today",
new PropertyChangedCallback(OnDayNameCaptionChanged),
new CoerceValueCallback(CoerceDayNameCaption)));
public string DayNameCaption
{
get { return (string)GetValue(DayNameCaptionProperty); }
set { SetValue(DayNameCaptionProperty, value); }
}
private static void OnDayNameCaptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;
}
private static object CoerceDayNameCaption(DependencyObject d, object value)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;
return null;
}
#endregion
#region CTOR
public MonthViewDayColumnHeader()
{
InitializeComponent();
this.DataContext = this;
}
#endregion
}
Usage:
<Grid>
<schedule:MonthViewDayColumnHeader DayNameCaption="Monday"
Height="50"
Width="120"/>
</Grid>
The text "Monday" doesn't show up.
WTF IS WRONG HERE!!!!
If it's not broken, fix it until it is
|
|
|
|
|
|
Thanks for your thoughtful response. That fixed it.
If it's not broken, fix it until it is
|
|
|
|
|
The reason why it's not working is the MonthViewDayColumnHeader class doesn't support INotifyPropertyChanged. It's being initialized, then updated with Monday after. If you take the existing and default it to 'Sunday' you should be able to see the default value.
On that note, I know it's an example but you should probably start off with MVVM in your learning process. Have the underlying layers implement the INotifyPropertyChanged and set the context to an appropriate view model.
|
|
|
|
|
Actually, it wasn't working because I'm a dumba$$...
private static object CoerceDayNameCaption(DependencyObject d, object value)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;value
return null;
}
changed it to
private static object CoerceDayNameCaption(DependencyObject d, object value)
{
MonthViewDayColumnHeader control = (MonthViewDayColumnHeader)d;
var dayNameCaption = control.DayNameCaption;value
return dayNameCaption ;
}
If it's not broken, fix it until it is
|
|
|
|
|
Yes and no. You shouldn't be using a callback in this case. The callback is circumventing the whole point of the binding. Taking my advice would fix it the appropriate way.
|
|
|
|
|
Well, actually, I put in the callback for testing and ended up breaking my code
If it's not broken, fix it until it is
|
|
|
|
|
I assume the rogue ;value is just a typo in your message?
var dayNameCaption = control.DayNameCaption;value
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You don't need to implement INotifyPropertyChanged when you're using dependency properties.
DependencyProperties or INotifyPropertyChanged ?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, you're correct. For some reason I was thinking the underlying source still need to be explicitly hooked, but it does not.
|
|
|
|
|
It should be,
<TextBlock Text="{Binding DayNameCaption, RelativeSource={RelativeSource FindAncestor, AncestorType={UserControl}}}"... /> You don't need the callback.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
I have been trying for several days to come up with a solution for the my application page. My page contains an upper section with a menu, page header, and two columns for a human head silhouette image and empty white section. That section works fine. What I have been trying to add to my page are two DataGrids side by side so it will create a single table of a total of four columns. Now on each DataGrid the first column is a Description and the second column is the Value it displayed for the Description. What I am trying to do is have a table on the page that appears to make up a single table with 17 rows of Description/values. I don't want either DataGrid to have a scroll bar and each not to be able to scroll. In some of the DataGrid cell a want a background color of blue. Now on the page this table is in a DockPanel with a height of 368 units. What I want is the DockPanel to have a scroll bar so both DataGrids can be scrolled up and down as a single table. First, I have found the it is almost impossible to change the background of a DataGrid Column's Cell. Next my DockPanel scroll bar does not appear and each of the DataGrids are still able to scroll. Below is both the XAML and the code behind. I am only showing 8 rows for testing. If anyone can help that would be great.
Page XAML
<ScrollViewer Height="368" Width="900" VerticalScrollBarVisibility="Auto">
<DockPanel Background="White" Height="368" VerticalAlignment="Top">
<DataGrid Name="main1" ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" BorderBrush="White" DockPanel.Dock="Left" HorizontalAlignment="Left" Width="495" >
<DataGrid.Columns>
<DataGridTextColumn FontSize="14" FontWeight="Bold" Header="Test Description" Binding="{Binding Description }" />
<DataGridTextColumn FontSize="14" FontWeight="Bold" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<DataGrid Name="main1" ScrollViewer.CanContentScroll="False" AutoGenerateColumns="False" BorderBrush="White" DockPanel.Dock="Left" HorizontalAlignment="Left" Width="495" >
<DataGrid.Columns>
<DataGridTextColumn FontSize="14" FontWeight="Bold" Header="Test Description" Binding="{Binding Description }" />
<DataGridTextColumn FontSize="14" FontWeight="Bold" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</ScrollViewer>
Code behind:
List<InformationValues> InformationValuess = new List<InformationValues>();
List<InformationValues> InformationValuess2 = new List<InformationValues>();
List<InformationValues> InformationValuess3 = new List<InformationValues>();
List<InformationValues> InformationValuess4 = new List<InformationValues>();
InformationValuess.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess2.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess3.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description1", Value = "Test Value1" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description2", Value = "Test Value2" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description3", Value = "Test Value3" });
InformationValuess4.Add(new InformationValues() { Description = "Test Description4", Value = "Test Value4" });
main1.ItemsSource = InformationValuess;
main2.ItemsSource = InformationValuess2;
|
|
|
|
|
Change your datasource to a single collection and use a datagrid.
Create a model to meet your view requirements either in the VM or code behind. It should probably have 4 properties for display and 2 object properties to have the underlying data object if you need to do any additional processing when the user interacts with the selected value.
Bind the single collection to a datagrid and forget your scrollviewer.
See if the datagrid supports a CellStyleSelector (I use Telerik tools and they have this concept). I'm pretty sure there are some implementations for the standard tooling out there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Using a single object with all four properties is definitely the way to go and solves all of my problems except changing the background color of some of the DataGrid cells to blue. I read several articles yesterday and tried to implement the code for turning different DataGrid cells to blue but was unable to get any of the procedures working. This DataGrid is not like the Telerik and has no cell style to do the job. If anyone has something that they have implemented working please let me know.
|
|
|
|
|
Add fields to the model for each cell you need couloured. Bind the cells background to the cell, it may need a converter if the background cannot process the string colour name.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
With WPF and MVVM, properties of the ViewModel are bound to UI elements. When a property changes, its set accessor calls OnPropertyChanged which in turn raises the PropertyChanged event of the INotifyProptyChanged interface.
But it is possible to call OnPropertyChanged (with the property name as argument) from anywhere in the ViewModel (and then you can't use the CallerMemberName attribute).
Now I'd like to ask you: how do you handle such cases? Do you call OnPropertyChanged from other places than the property_set ? Or do you change your code such that you call the property_set ? Or other ideas?
|
|
|
|