|
Resolved it, adding design time data helped...though weirdly with it working the design time data now looks wrong.
I'm not 100% this is fully correct, or the best or simplest way of doing this...but it does seem to work so far. I've got a few CollectionViewSource s, but the first and last are the only two relevant to this.
<Page.Resources>
<CollectionViewSource x:Key="unitViewSource"
Source="{Binding}" />
<CollectionViewSource x:Key="unitsServicesViewSource"
Source="{Binding Path=Services, Source={StaticResource unitViewSource}}" />
<CollectionViewSource x:Key="unitTypeViewSource"
d:DesignSource="{d:DesignData Source=/SampleData/UnitTypeSampleData.xaml}" />
<CollectionViewSource x:Key="unitNameViewSource" />
I needed the CollectionViewSource unitNameViewSource, so that I could set the ItemsSource on the ComboBox to something. If I didn't set it, or set it to {Binding} I got false values on the first record.
The ComboBox s are defined as:
<ComboBox Grid.Column="1"
Grid.Row="1"
Margin="3"
Name="businessAreaIdComboBox"
DisplayMemberPath="Name"
SelectedValuePath="Id"
SelectedItem="{Binding Path=BusinessArea}"
ItemsSource="{Binding Source={StaticResource unitNameViewSource}}">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
<ComboBox.InputBindings>
<KeyBinding Key="Delete"
Command="{Binding RelativeSource={RelativeSource AncestorType=Page}, Path=ClearComboBoxCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ComboBox}, Path=Name}" />
</ComboBox.InputBindings>
</ComboBox>
The other thing I think was important was to bind to BusinessArea and not the BusinessAreaId column. Let EF faff with translating that!
My code behind is then:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
viewSource = ((CollectionViewSource) (this.FindResource("unitViewSource")));
try
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (s, ev) =>
{
this.Dispatcher.Invoke(new Action(() =>
{
UIHelper.ProgressBarRun(true);
this.IsEnabled = false;
}));
context.Units.Load();
context.UnitTypes.Load();
};
worker.RunWorkerCompleted += (s, ev) =>
{
viewSource.Source = context.Units.Local;
unitTypeIdComboBox.ItemsSource = context.UnitTypes.Local;
UpdateComboBoxes();
this.Dispatcher.Invoke(new Action(() =>
{
UIHelper.ProgressBarRun(false);
navFirstButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
this.IsEnabled = true;
}));
};
worker.RunWorkerAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void UpdateComboBoxes()
{
var unitNames = context.Units.Local;
businessAreaIdComboBox.ItemsSource = unitNames;
divisionalUnitIdComboBox.ItemsSource = unitNames;
parentUnitIdComboBox.ItemsSource = unitNames;
}
If I used the unitNameViewSource, and set it (even to the same Units.Local), I got the issue where all three combo boxes displayed the same value. So I need the ViewSource, for the XAML ItemsSource binding, but then overwrite it in code...as I said this probably isn't the right way
The UpdateComboBoxes method is just a hangover from when I thought I would need to refresh them all after adding a new unit.
|
|
|
|
|
I have a NotificationInformation class which contains properties together with property changed events:
public string EmailUser
{
get { return _emailUser; }
set
{
_emailUser = value;
OnPropertyChanged("EmailUser");
}
}
The NotificationInformationRepository class contains the NotificationInformation classes in a List of NotificationInformation classes (List<NotificationInformation> )
When OnPropertyChanged fires on a NotificationInformation instance I want to be able to serialize the NotificationInformationRepository data in the List.
I have the serialization working correctly - my question is how do I go about subscribing to or picking up the OnPropertyChanged events from within the NotificationInformationRepository class?
I realise this is a basic WPF question but I am feeling dumb this weekend being unable to code this.
-----------------------------------------------------------------------------------------------------
Solution:
In NotificationInformation I have declared a delegate:
public delegate void ItemChanged();
[field: NonSerialized]
public ItemChanged ItemHasChanged;
public NotificationInformation(ItemChanged _itemChanged)
{
ItemHasChanged = _itemChanged;
}
public string EmailUser
{
get { return _emailUser; }
set
{
_emailUser = value;
OnPropertyChanged("EmailUser");
ItemHasChanged();
}
}
When I add a NotificationInformation to the NotificationInformationRepository List I pass in a reference to a method in NotificationInformationRepository that is used as the delegate.
It's not pretty
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
You are *way* over-thinking it (and you're right, what you did is not pretty and kinda breaks OO principles) . When you add an item to the NotificationInformationRepository, just subscribe to the INotifyPropertyChanged event. Your subscription handler would just be a method that does Save() or whatever you do to save the repository.
If you want to encapsulate it (which I would), you'd just add a new Add() overload to the NotificationInformationRepository that subscribes to the event. Of course, if you want to clean up properly, you should unsubscribe in a Delete() method and in the finalizer.
|
|
|
|
|
Thanks!
I subscribed to the INotifyPropertyChanged event and it worked.
I knew I was missing something obvious, I'm reasonably new to WPF and as you say this was over-thinking the issue.
I will look into the encapsulation suggestion.
Thanks again
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I need a reporting tool for use in a WPF app.
Requirements:
1. Preferably free
2. The report will probably NOT be too complex, so I don't need anything too complicated.
3. Easy to learn
4. Easy to deploy.
Any suggestions?
Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
Hi, may be you want to try this[^].
The best not free Reporting tool, for me is this[^].
--
Christian Amado
Software Engineer | MCPD: Windows Phone Developer | MCTS: Silverlight Developer
Please mark as answer, if helped you.
|
|
|
|
|
You pointed me to Telerik. I downloaded their Reporting Q2 2014 samples.
I can't get it to compile. There are 4 or 5 themes files that have to be included, or the viewer doesn't show up. Their tech support sent me this[^].
I followed it, and they theme files won't compile. Seems they are referencing other Telerik assemblies or namespaces that either don't exist or are wrong.
What version of their reporting are you using? Have you got this working?
If it's not broken, fix it until it is
|
|
|
|
|
Have you had a look at this[^]?
|
|
|
|
|
Pete,
I downloaded it.. I don't see a designer anywhere... Am I missing something?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
It uses XAML so it doesn't have a designer. That wasn't a requirement in your list. To be honest, the XAML is nice and clean. This is the sample Image report:
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xrd="clr-namespace:CodeReason.Reports.Document;assembly=CodeReason.Reports"
xmlns:xrbc="clr-namespace:CodeReason.Reports.Document.Barcode;assembly=CodeReason.Reports"
PageHeight="29.7cm" PageWidth="21cm" ColumnWidth="21cm">
<xrd:ReportProperties>
<xrd:ReportProperties.ReportName>ImageReport</xrd:ReportProperties.ReportName>
<xrd:ReportProperties.ReportTitle>Image Report</xrd:ReportProperties.ReportTitle>
</xrd:ReportProperties>
<xrd:SectionReportHeader PageHeaderHeight="2" Padding="10,10,10,0" FontSize="12">
<Table CellSpacing="0">
<Table.Columns>
<TableColumn Width="*" />
<TableColumn Width="*" />
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell>
<Paragraph>
<xrd:InlineContextValue PropertyName="ReportTitle" />
</Paragraph>
</TableCell>
<TableCell>
<Paragraph TextAlignment="Right">
<xrd:InlineDocumentValue PropertyName="PrintDate" Format="dd.MM.yyyy HH:mm:ss" />
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</xrd:SectionReportHeader>
<xrd:SectionReportFooter PageFooterHeight="2" Padding="10,0,10,10" FontSize="12">
<Table CellSpacing="0">
<Table.Columns>
<TableColumn Width="*" />
<TableColumn Width="*" />
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell>
<Paragraph>
</Paragraph>
</TableCell>
<TableCell>
<Paragraph TextAlignment="Right">
Page
<xrd:InlineContextValue PropertyName="PageNumber" FontWeight="Bold" /> of
<xrd:InlineContextValue PropertyName="PageCount" FontWeight="Bold" />
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</xrd:SectionReportFooter>
<Section Name="ReportBody" Padding="80,10,40,10" FontSize="12">
<Paragraph FontSize="24" FontWeight="Bold"><xrd:InlineContextValue PropertyName="ReportTitle" /></Paragraph>
<Paragraph>This is an image report example.</Paragraph>
<Paragraph FontSize="16" FontWeight="Bold">
Static Image
</Paragraph>
<Paragraph>
<Image Tag="dpd.jpg" Width="10cm" />
</Paragraph>
<Paragraph FontSize="16" FontWeight="Bold">
Dynamically created Images
</Paragraph>
<Paragraph>
<Image Name="imageDynamic1" Width="5cm" Height="5cm" />
<Image Name="imageDynamic2" Width="5cm" Height="5cm" />
</Paragraph>
</Section>
</FlowDocument>
|
|
|
|
|
Pete O'Hanlon wrote: It uses XAML so it doesn't have a designer. That wasn't a requirement in your list. To be honest, the XAML is nice and clean. This is the sample Image report:
To me it's assumed that you need a designer. Yes, XAML is nice & clean... and VERY time consuming. For anything other than a VERY simple report it would take all day to get laid out right.
I noticed on their site that someone asked for a designer. Nice idea for an add on to the project.
I can't see how any serious reporting can be done without a designer.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: and VERY time consuming Hmmm. I'm not sure I agree here. I can churn out XAML at a phenomenal rate.
|
|
|
|
|
I can too. Don't get me wrong. I love XAML
But for every little tweak, you would need to stop, compile, run the report (meaning fire up your app, get to the report, run it - OOPS that label isn't aligned right!!!
Stop, open XAML, tweak, repeat.
With a designer it's one & done.
If it's not broken, fix it until it is
|
|
|
|
|
If the report is simple and you have already worked getting the data to a form, maybe just roll your own print routine to generate the report? See Printing in WPF[^] for example?
|
|
|
|
|
If you want a report designer then you could always look at SyncFusion reports[^]. I'm a big fan of SyncFusion now. They have worked hard on the performance of their WPF products, and this really shows.
|
|
|
|
|
It's not free, but we've had a lot of success with DevExpress' XtraReports package[^]. One very nice thing about it is that you can use the same report in WinForms, WPF and ASP.NET contexts (Silverlight too... but who needs that any more?!).
Regards,
Richard
|
|
|
|
|
Searching for "WPF marquee text" throws up some results that look promising:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm trying to display a custom tooltip for Tree Nodes
I created this resource:
<ToolTip x:Key="treeItemToolTip"
DataContext="{Binding Path=PlacementTarget,RelativeSource={x:Static RelativeSource.Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="Revision:"/>
<TextBlock Grid.Row="0"
Grid.Column="1"
Text="{Binding RevisionNumber}"/>
</Grid>
</ToolTip>
then in my Tree I have
<controls:TreeViewEx BorderThickness="0"
Margin="5"
ItemsSource="{Binding Nodes}"
IsManipulationEnabled ="True"
Visibility="{Binding ShowTree, Converter={StaticResource visibilityConverter}}"
ToolTip="{StaticResource treeItemToolTip}">
</controls:TreeViewEx>
Yet when I run it, the Output window tells me that the tooltip can't find it's data on the TREEVIEW, not the nodes.
The data for the tooltip is on each node. How do I correctly bind the Tooltip to the node's data?
If it's not broken, fix it until it is
|
|
|
|
|
You are setting the tooltip on the tree itself. You want to set it on the items.
|
|
|
|
|
Ok, I see. How do I point it to the item instead?
If it's not broken, fix it until it is
|
|
|
|
|
Put it in your TreeViewItem style. If you don't have one, just create one with a single setter.
<Setter Property="ToolTip" Value="{StaticResource treeItemToolTip}" />
|
|
|
|
|
First I want to apologize for the lack of experience in English.
I am Brazilian and I'm using google translator to send this question.
I have a WPF project where I use a dll as resource dictionary and need to import into another dll then then use in my project.
But when I try to import the first dictionary, I encounter the error
"An error occorred while finding the resource dictionary".
've Researched everything I imagined trying to solve.
BuildAction the ResourceDictionary of this dll as the first page. (already tried as resource)
|
|
|
|
|
Hi All,
I am trying to convert jpg image to vector image in xaml file but the image gets blurred. Tool I used was Microsoft Expression Design. Tried with online conversion tool as well but result was same. Kindly suggest how a good quality vector image can be converted and plugged it in to silver light project xaml file.
http://www.bodurov.com/BitmapVectorizer/[^]
Regards
Deep
|
|
|
|
|
Hi guys,
I am new to WPF and I have a question about dynamic tab generation with tab control.
I would like to build template pages that would be called into a new tab of a tab control and bind its content to DB. For instance, I want to load an invoice from a list. It creates a tab, fills it with the invoice display page (frame?) and populates it with the info. If I go back to my list and load another invoice, it loads a second instance of my invoice display page into a new tab and populates it with the new invoice.
Is dynamic tab generation with the WPF tab control + frames the right way to go?
Thanks
|
|
|
|
|
Certainly adding the invoices to dynamic tabs would be reasonably straightforward. I'm not sure what you're trying to do with the Frame though.
|
|
|
|