|
Thanks for the reply
I am planning to have a generic function to export the Listview to Excel.
But different listboxes have different datasources (observable collection).
So I would like to find a way to iterate throgh GridView/ListView as in dataGrid and read cells.
|
|
|
|
|
Ok, then..
Iterate the columns.
Extract the path names for each binding source bound to each column.
Use the extracted name to reflect on the rows in the itemsource and "getvalue" the property values.
Export the values.
Easy.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks for the fast reply.
Can you give me a sample code for that please.
At least a link with similar example would be helpful
Thanks in advance
|
|
|
|
|
Search on "sorting gridview" columns.
It will give you a start on "reflecting" lists and grids.
I don't write code for free.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I'm trying to create a navigation bar like this.
Yesterday I posted on this, and I was unable to get it to work right.
So, what I'm thinking is that each blue bar would be an Expander. Each Expander could then have either another Expander, or a list of hyperlinks.
I want to make it flexible enough so that by simply adding data to a group in the model, they appear as a group in the nav bar.
Here's what I got so far:
Model
public class NavigationItem : BindableBase
{
public int ItemId { get; set; }
public string Caption { get; set; }
public NavigationItemType ItemType { get; set; }
public ObservableCollection<NavigationItem> NavigationItems { get; set; }
}
XAML
<pre><ListBox Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding NavigationBarItems}">
<pre>
<ListBox.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Caption}">
<ListBox ItemsSource="{Binding NavigationItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Caption}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
This it what I have now.
https://1drv.ms/i/s!AjBmoYAYz_v2ggqcuk5OS5YW1KDO
You can see that the first group doesn't have the subgroups.
How do I make these subgroups in the XAML?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 1-Dec-17 12:46pm.
|
|
|
|
|
What is wrong with a treeview, Telerik (and many others) have an outlook bar type tool that may be what you are looking for.
Personally I would use a treeview and use the click event to toggle the expansion. This assumes you don't need a visual cue to tell if there are children under a node.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a WPF TreeView that I'm trying to load with the following items:
Projects
- Builder 1
- Project 1a
- Project 1b
- Builder 2
- Project 2a
- Project 2b
Companies
- Company 1
- Company 2
Employees
- Employee 1
- Employee 2
Problem
The Companies and Employees nodes both load fine. For the first level all I see is "Projects". The Builders and Projects under them don't appear. I'm guessing my HierarchicalDataTemplate is wrong but I can't see it. Anyone see what's wrong?
Thanks
Models
public class NavigationCategory : BindableBase
{
public string Caption { get; set; }
public NavigationGroup Group { get; set; }
public ObservableCollection<NavigationCategory> Categories { get; set; }
public ObservableCollection<NavigationItem> NavigationItems { get; set; }
}
public class NavigationItem : BindableBase
{
public int ItemId { get; set; }
public string Caption { get; set; }
public ViewType ViewType { get; set; }
}
The XAML
<TreeView Name="Navigation"
Grid.Row="1"
Grid.Column="0"
ItemsSource="{Binding NavigationBarItems}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type models:NavigationCategory}"
ItemsSource="{Binding NavigationItems}">
<TextBlock Text="{Binding Path=Caption}" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type models:NavigationItem}">
<TextBlock Text="{Binding Path=Caption}" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
View Model
private ObservableCollection<NavigationCategory> _NavigationBarItems;
public ObservableCollection<NavigationCategory> NavigationBarItems
{
get { return _NavigationBarItems; }
set
{
if (_NavigationBarItems != value)
{
_NavigationBarItems = value;
RaisePropertyChanged("NavigationBarItems");
}
}
}
private void LoadNavBar()
{
NavigationBarItems = new ObservableCollection<NavigationCategory>
{
new NavigationCategory
{
Group = NavigationGroup.Projects,
Caption = "Projects",
Categories = new ObservableCollection<NavigationCategory>
{
new NavigationCategory
{
Group = NavigationGroup.Builders,
Caption = "Builder 1",
NavigationItems = new ObservableCollection<NavigationItem>
{
new NavigationItem
{
ItemId = 101,
Caption = "Project 1a",
ViewType = ViewType.Project
},
new NavigationItem
{
ItemId = 102,
Caption = "Project 1b",
ViewType = ViewType.Project
}
}
},
new NavigationCategory
{
Group = NavigationGroup.Builders,
Caption = "Builder 2",
NavigationItems = new ObservableCollection<NavigationItem>
{
new NavigationItem
{
ItemId = 201,
Caption = "Project 2a",
ViewType = ViewType.Project
},
new NavigationItem
{
ItemId = 202,
Caption = "Project 2b",
ViewType = ViewType.Project
}
}
}
}
},
new NavigationCategory
{
Group = NavigationGroup.Companies,
Caption = "Companies",
NavigationItems = new ObservableCollection<NavigationItem>
{
new NavigationItem
{
ItemId = 301,
Caption = "Company 1a",
ViewType = ViewType.Company
},
new NavigationItem
{
ItemId = 302,
Caption = "Company 1b",
ViewType = ViewType.Company
}
}
},
new NavigationCategory
{
Group = NavigationGroup.Employees,
Caption = "Employees",
NavigationItems = new ObservableCollection<NavigationItem>
{
new NavigationItem
{
ItemId = 401,
Caption = "Employee 1a",
ViewType = ViewType.Employee
}
}
}
};
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Yes I have, and I followed that design - at least I think I did.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You category and item are different structure.
I create one list of TreeNode with a collection of TreeNodes as the child items. NodeLabel is the display field and a tag (object) property holds the populating record (project or builder or item)
I have a recursive loading method that load the appropriate source into the TreeNode/ChildItems based on relationship keys.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: You category and item are different structure.
Yup.
Eventually the Category will be styled like a colored block, and the items will be hyperlinks. They're two entirely different classes. This isn't a problem with a treeview and I've done it before. Just can't figure out why I't not working here.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yah you seem to do a lot more styling and graphical stuff than I do - bank, finance department, all they want is the numbers.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I just changed it like you did it and it's working fine. Much simpler
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
This did it
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Anyone using MahApps that can answer some questions? The documentation is sparse and almost non-existent.
For starters, let's say I put a border on a view. I want the background and/or border color of the border to change when my theme changes. How do I do this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have you looked at the github sample here[^]?
This space for rent
|
|
|
|
|
public class MyViewModel
{
private readonly IProcessData _processData;
[ImportingConstructor]
public MyViewModel(IProcessData processData)
{
_processData = processData;
}
}
public interface IProcessData
{
string ReadData();
}
[Export("ReadSerialData", typeof(IProcessData))]
public class ReadSerialData : IProcessData
{
public string ReadData()
{
throw new NotImplementedException();
}
}
[Export("ReadSQLData", typeof(IProcessData))]
public class ReadSQLData : IProcessData
{
public string ReadData()
{
throw new NotImplementedException();
}
}
Based on requirement at run-time I want to load any of the concrete class implementation.
|
|
|
|
|
What you've got there won't work. The contract names on the two exports don't match the default contract name on the import, so there's no match.
If you know which class you want to import at compile-time, then you can use the [Import] attribute to pick the right one:
[ImportingConstructor]
public MyViewModel([Import("ReadSQLData")] IProcessData processData)
If you don't know which one you want to use until runtime, you'll need to write some code to pick the right export. For example, you could use a combination of [ImportMany] and export metadata:
Metadata and Metadata Views | Attributed Programming Model Overview (MEF) | Microsoft Docs[^]
public interface IProcessDataMetadata
{
string Name { get; }
}
[Export(typeof(IProcessData)), ExportMetadata("Name", "ReadSerialData")]
public class ReadSerialData : IProcessData { ... }
[Export(typeof(IProcessData)), ExportMetadata("Name", "ReadSQLData")]
public class ReadSQLData : IProcessData { ... }
public interface IMyViewModelFactory
{
MyViewModel Create(string processorName);
}
[Export(typeof(IMyViewModelFactory))]
public class MyViewModelFactory : IMyViewModelFactory
{
[ImportingConstructor]
public MyViewModelFactory([ImportMany] IEnumerable<Lazy<IProcessData, IProcessDataMetadata>> processors)
{
Processors = processors.ToList();
}
public IReadOnlyCollection<Lazy<IProcessData, IProcessDataMetadata>> Processors { get; }
public MyViewModel Create(string processorName)
{
Lazy<IProcessData, IProcessDataMetadata> processor = Processors.FirstOrDefault(p => p.Metadata.Name == processorName);
if (processor == null) throw new ArgumentException($"Unknown processor '{processorName}'.", nameof(processorName));
IProcessData processData = processor.Value;
return new MyViewModel(processData);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In a WPF Application we use tabs and an navbarcontrol from devexpress.
With the tabs we had the problem that it always recreates it's children.
The solution for that I have found here: WPF TabControl: Turning Off Tab Virtualization[^]
Now the same problem exists with the navbarcontrol from devexpress.
How can I achieve the goal of the child items from the navbarcontrol not always recreates it's children, so that the databinding works!
Thanks in advance !
|
|
|
|
|
I would simply use the tabs with no content; above my "viewing" area; and use them as "selectors" to hide / display user controls containing my content.
It's the "look" that matters; not the implementation (in this case).
(Or go one further, and create your own "tab ribbon"; using buttons with rounded tops, for example; to toggle display areas).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
That is not what I looking for.
we use the mvvm pattern.
So, is there a possibility to implement virtualization off the tabs off the navbarcontrol of devexpress or similar ?
|
|
|
|
|
Anything is possible.
You want to waste your time coming up with a "MVVM pattern for tab virtualization" instead of shipping, be my guest.
What's the "business case" for that pattern in this case?
Does the fact that nobody else is interested tell you anything?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
First of all, I'm not searching for tab virtualization.
1) The application is according to the mvvm architecture that I wish to maintain.
2) The application have 2 tabs "Tab 1" and "Tab 2" (tabcontrol) that we used tab caching followed by the solution of ikriv: WPF TabControl: Turning Off Tab Virtualization
3) Within "tab 1" stays general info.
4) Within "tab 2" stays left side the navigation and right side the content like the picture here :
Sample picture
Clicking on"Inbox" and "Outbox" shows usercontrols on the right side.
On both Usercontrols stays an label with an textbox where I applied databinding for the saved state
The situation now: When I switch from "Tab2" Inbox item where i filled in the textbox "100" as example to tab 1. It works like a charm, when switching back to the inbox my value "100" is saved with thanks to the solution of ikriv.
The problem: When I switch from "Tab2" Inbox to another item within Tab2 like "Outbox" and switching back the data is lost. The value of "100" is gone. It will be resetted to "0"
The Inbox / Outbox/ .. items like in picture are not tabs but the NavBarControl from DevExpress.
The problem is when switching by the items of the control of devexpress.
Thats the thing I'm looking/searching for.
Hopefully is my question now more clarified.
|
|
|
|
|
I dumped DevExpress when they couldn't even maintain the simplest compatibility from one release to the next.
My take is that DevExpress is "nice" but gets "smelly" the deeper you need to go; though I first got it for the charting (which has long been surpassed by others).
Hacking your own software is one thing; with 3rd parties, it's a moving target.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
On my Main Window is a list of Vehicle Models:
public class MainWindowViewModel : INotifyPropertyChanged
{
private List _Vehicles;
public List Vehicles
{
get { return _Vehicles; }
set
{
if (_Vehicles != value)
{
_Vehicles = value;
RaisePropertyChanged("Vehicles");
}
}
}
private bool _IsValid;
public bool IsValid
{
get { return _IsValid; }
set
{
if (_IsValid != value)
{
_IsValid = value;
RaisePropertyChanged("IsValid");
}
}
}
}
Here's the VehicleModel:
public class VehicleModel : ModelBase
{
private string _VehicleName;
public string VehicleName
{
get { return _VehicleName; }
set
{
if (_VehicleName != value)
{
_VehicleName = value;
RaisePropertyChanged("VehicleName");
}
}
}
private bool _IsActive;
public bool IsActive
{
get { return _IsActive; }
set
{
if (_IsActive != value)
{
_IsActive = value;
RaisePropertyChanged("IsActive");
}
}
}
}
In the ViewModel, how can I tell when a VehicleModels' IsActive has changed? The IsValid property can only be True when one or more Vehicles is active.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|