|
|
I have control element and when i am doing drag and drop then that control have not image effects while doing operation. so please tell me a running examples for my requirement.
Hint is here demo of requirement image while drag and drop in wpf.
Thanks in advance.
Kalu Singh
|
|
|
|
|
I want to know the best practice for reusing the resources in WPF. I am using lot of resources in my application. For example Resource A,B,C and D. Resource A is used in Control A, Resource B is used in Control B, Resource A,C,D is used in Control C.
I found below three ways but i want to know which one is the best practice.
1. Adding all the resource in a Resource Dictionary file and use the resource dictionary in all the Controls.
2. Create separate resource dictionary file for each resource and Merge only the required resource dictionary in controls.
3. Duplicating the required resource in each control.
|
|
|
|
|
I see only 2 options and an idiotic suggestion.
I would go for something in between, group the resources by functionality and create a number of "libraries"
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft Holmes ,
Mycroft Holmes wrote: I would go for something in between, group the resources by functionality
Take if the Resource A and B are grouped by functionality to a Single Resource File. What if i used this resource in Control A which requires only Resource A. Is it ok to have Resource B also in the same file event thought it is not required for control A?. My concern is also about the memory and Performance.
|
|
|
|
|
Sorry, I have not considered memory usage as an issue since the 90s but I would not hesitatein using 2 resource libraries for a single control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi!
I have a WpfApplication with a TreeView and a Button.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="tvTree">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding List}" DataType="{x:Type local:BaseNode}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Header}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Button Width="20" Height="20" Content="Click" Click="Button_Click" />
</Grid>
</Window>
The TreeView's ItemsSource property will be populated from a list based on the BaseNode class. That class look like this:
public class BaseNode
{
System.Collections.ObjectModel.ObservableCollection<BaseNode> list = new System.Collections.ObjectModel.ObservableCollection<BaseNode>();
string header;
public BaseNode(string header)
{
this.header = header;
}
public string Header
{
get { return header; }
set { header = value; }
}
public System.Collections.ObjectModel.ObservableCollection<BaseNode> List
{
get { return list; }
set { list = value; }
}
}
The MainWindow.cs have this code:
public partial class MainWindow : Window
{
BaseNode a = new BaseNode("Base");
BaseNode b = new BaseNode("Sub1");
BaseNode c = new BaseNode("Sub2");
BaseNode ba = new BaseNode("Sub1Sub1");
BaseNode baa = new BaseNode("Sub1Sub1Sub1");
public MainWindow()
{
InitializeComponent();
a.List.Add(b);
a.List.Add(c);
b.List.Add(ba);
ba.List.Add(baa);
tvTree.ItemsSource = a.List;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
b.Header = "NewHeader";
}
}
Question 1:
When I click the button I would like to change the Header property of one of the BaseNodes. But the code for the Button.Click event won't do the trick. Just setting the BaseNode.Header property seem not to be enough. Instead I need to alter the Button.Click callback to:
private void Button_Click(object sender, RoutedEventArgs e)
{
b.Header = "NewHeader";
tvTree.ItemsSource = null;
tvTree.ItemsSource = a.List;
}
This does the job but seem to be very overkill for such a small thing.
Is there a better way to make the TreeView show the new value of the BaseNode.Header property?
Question 2:
Image I have populated the same TreeView with a bunch of BaseNode objects forming a tree with many branches of BaseNodes as well as branches in branches. I lack a way to, manually by code, open or close a branch in the TreeView.
I have found out that this is supported for the TreeViewItem control which have the IsExpanded property. My BaseNode class don't have such a property and including one I highly doubt it will "solve the problem".
With the TreeView.SelectedItemChanged event I can select any BaseNode in the TreeView and find out the actual BaseNode instance I selected. From this point I would like to be able to open or close the nested BaseNodes.
How to open or close a nested node in the TreeView which is not a TreeViewItem?
Best regards
/Mc_Topaz
|
|
|
|
|
In regards to Question #1, your BaseNode needs to PROPERLY implement INotifyPropertyChanged on the Header and List properties.
In regards to Question #2, yes, the IsExpanded property is in the TreeViewItem. HierarchialDataTemplate doesn't support binding to that out of the box. However, you can easily derive a class HierachialDataTemplateEx which exposes an IsExpanded property and override the ValidateTemplatedParent method and bind it to TreeViewItem.
|
|
|
|
|
Thanks SledgeHammer01!
I solved Question 1.
But I don't understand how to solve Question 2 by your explanation. I derived the HierarchicalDataTemplate class to this:
public class HierachialDataTemplateEx : HierarchicalDataTemplate
{
bool isExpanded = false;
public bool IsExpanded
{
get { return isExpanded; }
set { isExpanded = value; }
}
protected override void ValidateTemplatedParent(FrameworkElement templatedParent)
{
}
}
But I'm stuck after that. Can you continue my code and point me in the correct direction?
Also I got some further question for this solution:
1) Does this mean I need to stop using my BaseNode class and use TreeViewItem instead?
2) Using an derived version of HierarchicalDataTemplate class, does this mean my XAML code for the TreeView must be altered?
/Mc_Topaz
|
|
|
|
|
The way you have it set up above, you'll only be able to control the IsExpanded "once" (at creation of the node). I.e. create a node expanded. If that is not sufficient and you need to be able to expand and collapse at will, you'll need to go a slightly different route. It is more complicated, so I won't go into that unless you need it .
Yes, you will need to slightly modify your XAML (assuming your namespace is local):
<local:HierarchialDataTemplateEx IsExpanded="True" ... >
</local:HierarchialDataTemplateEx>
In your ValidateTemplateParent() method, you just do something like:
base.ValidateTemplatedParent(templatedParent);
// set the properties on the TreeViewItem
if ((object)templatedParent != null)
{
TreeViewItem tvi = templatedParent.TemplatedParent as TreeViewItem;
if ((object)tvi != null)
tvi.IsExpanded = IsExpanded;
That should be sufficient for most use cases (creating a node in its expanded state). As I mentioned above, you need to do additional stuff if you need to control expansion state dynamically or get the node expansion state at runtime for saving expansion state, etc.
However, this basic way will let you for example create the top level expanded and the rest of the levels collapsed.
|
|
|
|
|
Thanks again and for your effort!
I need to re-evaluate this. Maybe I don't need this full control of the TreeView.
|
|
|
|
|
I am building a WPF application in which I need to do some OCR. I understand that it is possible to use the Microsoft Office Document Imaging 12.0 Type Library in Office 2007. However, I want my application to run also without office 2007 installed. Is there a separate download of Microsoft Office Document Imaging 12.0 Type Library that I can use for this purpose. I assume that all I need to do is to reference the appropriate dll in my application - correct?
NOTE: in local system my WPF Application working Fine.
Local system having Office 2007. but i want to run with out office..
any solution.... plz.
Nazeerpc
|
|
|
|
|
A quick google search[^] reveals that:
From Wikipedia[^]:
Microsoft Office Document Imaging (MODI) is a discontinued Microsoft Office application that supports editing documents scanned by Microsoft Office Document Scanning. It is first introduced in Microsoft Office XP and is included in Office 2003...
The description clearly indicates what you should be doing now...
It is not available as a separate product anywhere, even not in later versions of office
See this: A C# Project in Optical Character Recognition (OCR) Using Chain Code[^]
And more results...[^]
Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas.
Carl von Clausewitz
Source
|
|
|
|
|
Hi
Any help would be very appreciated.
i have a listbox defined in the MainPage.xaml which a bind to a collection of nested objects (boxes).
<ListBox x:Name="MyListBox"
ItemTemplate="{StaticResource NestedDataTemplate}"/>
The box:
public class Box
{
public string BoxName { get; set; }
public ObservableCollection<Box> Boxes { get; set; }
}
I fill each child collection of each box with a single box and I do that up to 15 times, so that the hierarchy contains up to 15 levels.
Box -Box --Box ---Box
...... 15 times
In the handler of the loaded event of the MainPage.xaml.cs the collection is populated like so:
ObservableCollection<Box> boxCollection = new ObservableCollection<Box>();
Box lastBox = new Box();
lastBox.BoxName = "Box Nr. 1";
lastBox.Boxes = new ObservableCollection<Box>();
for (int i = 1; i < 15; i++)
{
Box newBox = new Box();
newBox.BoxName = "Box Nr. " + (i + 1);
newBox.Boxes = new ObservableCollection<Box>();
newBox.Boxes.Add(lastBox);
lastBox = newBox;
}
boxCollection.Add(lastBox);
MyListBox.ItemsSource = boxCollection;
The listbox's items template is a hierarchical data template defined in the resource section of App.xaml.
<sdk:HierarchicalDataTemplate x:Key="NestedDataTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Grid.RowSpan="2" Background="LightGray" Opacity="0.5"/>
<TextBlock Text="{Binding BoxName}"/>
<ListBox Grid.Row="1" ItemsSource="{Binding Boxes}" ItemTemplate="{StaticResource NestedDataTemplate}"/>
</Grid>
</sdk:HierarchicalDataTemplate>
When I run the app, it crashes and throws the following exception which can be investigated in the Application_UnhandledException handler in the App.xaml.cs.
The exception:
Error HRESULT E_FAIL has been returned from a call to a COM component.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth
Note: If I reduce the amount of hierarchy layers of the box collection, everything works fine.
Please help, I have been struggling for several days. I cannot find anything in forums or blogs.
Thank you
|
|
|
|
|
It should be reasonably obvious you are running up against a limitation of the tool, possibly unpublished. Try using a treeview, it is the control designed to do this type of job.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am implementing a Alerts Section Like This[^] in my application's Dashboard.
All or some of the text can be a hyperlink, with different commands bound to the links. The content of the messages will be automatically generated.
My first thought was have a table like this:
ImageName MessageDate Message ================================================================================================================
vehicle.jpg 2014-05/06 Vehicle Ford F150 Serial # ^L^256565^L^ has maintenance item ^L^Oil Change^L^ ready.
So it would look like:
"Vehicle Ford F150 Serial # 256565 has maintenance item Oil Change ready."
Clicking the serial # would open the vehicle screen. The Oil Change link would open the Maintenance screen.
I would then need to include in the message an action for each link. Like the link symbol, I could follow it with an enum item to denote what type of screen to open. And I would also need the PK's in there also.
Then, when the dashboard item is loaded, it would use a flow panel with both text and links in the data template so the Message column can wrap.
All this is fine, but it feels weird. Anyone done anything like this? Anyone got a better approach?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: an action for each link Exactly, but it seems that you just happened to use the correct word. System.Action is the class to use, or (more typical in WPF) a Command object (take a look at the Command Pattern ). When the link is clicked, you call the Invoke() method of the Action object.
|
|
|
|
|
Hi ,
I am currently developing an application but I need to have to switch between two languages , but I can't do it .
In fact , I created two Resources files for both languages and I set them to public and then then I put the propertie to Static as mentioned in many tutorials .
Thank you so much for your help.
My code written :
App.xaml.cs
public App()
{
if (Presentation.ViewModels.LoginWindow.LanguageSelect != null)
{
if (Presentation.ViewModels.LoginWindow.LanguageSelect.Equals("Italian"))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
}
}
else
{
Console.WriteLine("Verify the choosig langa=uage!");
}
}
ViewModel:
private string selectedLanguage;
public static string LanguageSelect;
public string SelectedLanguage
{
get
{
return selectedLanguage;
}
set
{
selectedLanguage = value;
RaisePropertyChanged("SelectedLanguage");
LanguageSelect = selectedLanguage.ToString();
}
}
And I the view.xaml
<ComboBox x:Name="MyCombo" Height="23" Width="90" HorizontalAlignment="Right" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Margin="20" IsEditable="False" Background="DarkCyan" Foreground="Blue"></ComboBox>
|
|
|
|
|
I have a treeview bound to a collection of Employees. Each Employee has one or more HoursWorked entity in a property called HoursWorked.
The HierarchicalDataTemplate has an Add button in it to add a new Hours Worked node under it.
Each hours worked node DataTemplate has a Remove button next to it. When it's clicked I'd like to pass both the Employee and the HoursWorked entity.
So I have:
<!--Employee-->
<HierarchicalDataTemplate DataType="{x:Type models:WorkDoneEmployeeInfoModel}"
ItemsSource="{Binding HoursWorked}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="Employee:"
VerticalAlignment="Center"
FontWeight="Bold"/>
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding EmployeeName}"/>
<Button Grid.Column="2"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.AddHoursCommand}"
CommandParameter="{Binding}"
VerticalAlignment="Center"
Height="22"
Width="22"
Margin="10,3,3,3">
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/add_256.png"
Height="16"
Width="16"/>
</Button>
</Grid>
</HierarchicalDataTemplate>
<!--Hours Worked-->
<DataTemplate DataType="{x:Type models:WorkDoneHoursWorkedModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="Time In:"
VerticalAlignment="Center"
FontWeight="Bold"/>
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding WorkStartDateTime}"/>
<TextBlock Grid.Column="2"
VerticalAlignment="Center"
Text="Time Out:"
FontWeight="Bold"/>
<TextBlock Grid.Column="3"
VerticalAlignment="Center"
Text="{Binding WorkEndDateTime}"/>
<Button Grid.Column="3"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.SubtractHoursCommand}"
VerticalAlignment="Center"
Height="22"
Width="22"
Margin="10,3,3,3">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MyMultiConverter}">
<!--The EmplyeeEntity-->
<Binding Path=""/> <===== WHAT GOES HERE? ===========
<!--The HoursWorked entity-->
<Binding Path="{Binding}"/>
</MultiBinding>
</Button.CommandParameter>
<Image Source="/FMG.UI.WPF.Shared;component/Media/Images/subtract_256.png"
Height="16"
Width="16"/>
</Button>
</Grid>
</DataTemplate >
So in the bottom template, I am passing the WoursWorked entity, but how do I set up the XAML to pass the parent node?
Thank you
[EDIT - RESOLVED]
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type TreeViewItem}, AncestorLevel=2}"/>
<Binding RelativeSource="{RelativeSource AncestorType={x:Type TreeViewItem}, AncestorLevel=1}"/>
</MultiBinding>
</Button.CommandParameter>
If it's not broken, fix it until it is
modified 2-May-14 18:04pm.
|
|
|
|
|
I have a DP called FullName. When it changes, I need to parse it and add it to an instance property of type List<<string>> FileAsOptions.
So, when I have
"Joe Smith"
or
"Smith, Joe"
they both get added to the list property.
The FullName property is a DP, and the FileAsOptions is an instance property. It's not a DP because I don't want it to be bindable.
So the FullName DP's change callback calls a private method that parses the name and add it to the instance list
The problem is that the instance property needs to call RaisePropertyChanged, which only works on instance properties. So the property cannot be static.
Here's the code:
public partial class ContactCard : _UserControlBase
{
public ContactCard()
{
InitializeComponent();
LayoutRoot.DataContext = this;
}
private List<string> _FileAsOptions;
public List<string> FileAsOptions
{
get { return _FileAsOptions; }
set
{
if (_FileAsOptions != value)
{
_FileAsOptions = value;
RaisePropertyChanged("FileAsOptions");
}
}
}
public string FullName
{
get { return (string)GetValue(FullNameProperty); }
set { SetValue(FullNameProperty, value); }
}
public static readonly DependencyProperty FullNameProperty = DependencyProperty.Register(
"FullName", typeof(string), typeof(ContactCard),
new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnFullNamePropertyChanged)));
private static void OnFullNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var card = sender as ContactCard;
}
private void setFileAsOptions(string fullName)
{
FileAsOptions = new List<string>();
if (!string.IsNullOrEmpty(fullName))
{
string[] words = fullName.Split(' ');
if (words.Length == 1)
{
FileAsOptions.Add(words[0]);
}
if (words.Length == 2)
{
FileAsOptions.Add(string.Format("{0} {1}", words[0], words[1]));
FileAsOptions.Add(string.Format("{0}, {1}", words[1], words[0]));
}
}
}
}
In summary, I need to be able to call the setFileAsOptions from the DP, which is static.
What's the right approach here?
If it's not broken, fix it until it is
|
|
|
|
|
Unless I've misread your question, it's quite simple!
private static void OnFullNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var card = sender as ContactCard;
card.setFileAsOptions((string)e.NewValue);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
LOL. I must be totally blind.. It's been a long day already.
Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
I am creating a user control. I will be using this user control in a few different apps. Once it's done I'll include its assembly in my project, reference it, and use it in my XAML somewhere. Pretty standard.
The question is... How do I apply a different set of styles to it based on the app I'm in?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The simplest way to achieve this is to have application level themes. In other words, in App A - you would set the styles for your control to be the ones you want in App A; in App B you set the styles for the control based on the ones you want in App B, and so on. Make sure you have a default theme for your control in place as well.
|
|
|
|
|
Ok, so create a theme. Isn't a theme just a collection of styles?
If it's not broken, fix it until it is
|
|
|
|