Skip to content

Commit 89fe5fa

Browse files
JMJM
authored andcommitted
Modified the sample app to let the end user change the XamDataPresenter Theme.
1 parent 441369e commit 89fe5fa

2 files changed

Lines changed: 58 additions & 19 deletions

File tree

DataPresenter.DataSources.OData/DataPresenter.DataSources.OData.SampleApp/MainWindow.xaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@
7979
<!-- Dropdown list of publicly accessible ODATA SERVICES-->
8080
<TextBlock Text="ODATA SERVICES" Style="{StaticResource HeaderText1}"/>
8181
<ComboBox x:Name="cboOdataSources" SelectionChanged="cboOdataSources_SelectionChanged" Style="{StaticResource ComboBoxText}">
82-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Orders" Description="Northwind Orders"/>
83-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Employees" Description="Northwind Employees"/>
84-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Suppliers" Description="Northwind Suppliers"/>
85-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="CompanySales" Description="AdventureWorks Company Sales"/>
86-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="ProductCatalog" Description="AdventureWorks Product Catalog"/>
87-
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="WorkOrderRouting" Description="AdventureWorks Workorder Routing"/>
8882
<local:DataSourceConfigurationInfo BaseUri="http://data.scottsdaleaz.gov/Planning/BuildingPermits.svc" EntitySet="BuildingPermits" Description="Scottsdale Building Permits">
8983
<!-- Limit the amount of data fetched from this OData service by setting the DesiredFIelds property. Refer to
9084
the cboOdataSources_SelectionChanged event handler code in MainWindow.xaml.cs to see how we apply these settings when
@@ -103,6 +97,12 @@
10397
<local:DataSourceConfigurationInfo BaseUri="http://data.scottsdaleaz.gov/MunicipalServices/CapitalImprovementProjects.svc" EntitySet="Projects" Description="Scottsdale Capital Improvement Projects"/>
10498
<local:DataSourceConfigurationInfo BaseUri="http://data.scottsdaleaz.gov/Finance/BusinessLicenses.svc" EntitySet="BusinessLicenses" Description="Scottsdale Business Licenses"/>
10599
<local:DataSourceConfigurationInfo BaseUri="http://data.scottsdaleaz.gov/Purchasing/Solicitations.svc" EntitySet="Solicitations" Description="Scottsdale Purchasing Solicitations"/>
100+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Orders" Description="Northwind Orders"/>
101+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Employees" Description="Northwind Employees"/>
102+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/V4/Northwind/Northwind.svc" EntitySet="Suppliers" Description="Northwind Suppliers"/>
103+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="CompanySales" Description="AdventureWorks Company Sales"/>
104+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="ProductCatalog" Description="AdventureWorks Product Catalog"/>
105+
<local:DataSourceConfigurationInfo BaseUri="http://services.odata.org/AdventureWorksV3/AdventureWorks.svc" EntitySet="WorkOrderRouting" Description="AdventureWorks Workorder Routing"/>
106106
<local:DataSourceConfigurationInfo BaseUri="http://packages.nuget.org/v1/FeedService.svc" EntitySet="Packages" Description="NuGet Packages"/>
107107
</ComboBox>
108108
<CheckBox x:Name="chkNullOutDatasource" IsChecked="True" Style="{StaticResource CheckBoxText}">Null out datasource before setting new</CheckBox>
@@ -185,6 +185,7 @@
185185

186186
<Grid.RowDefinitions>
187187
<RowDefinition />
188+
<RowDefinition />
188189
</Grid.RowDefinitions>
189190

190191
<TextBlock Grid.Row="0" Grid.Column="0" Text="VIEW" Style="{StaticResource LabelText}"/>
@@ -194,14 +195,17 @@
194195
<sys:String>CarouselView</sys:String>
195196
<sys:String>TreeView</sys:String>
196197
</ComboBox>
198+
199+
<TextBlock Grid.Row="1" Grid.Column="0" Text="THEME" Style="{StaticResource LabelText}"/>
200+
<ComboBox x:Name="cboThemes" Grid.Row="1" Grid.Column="1" SelectionChanged="cboThemes_SelectionChanged" Margin="2" Style="{StaticResource ComboBoxText}"/>
197201
</Grid>
198202

199203
</StackPanel>
200204
</StackPanel>
201205

202206
<GridSplitter Grid.Column="1" Width="7" Margin="2,0" Background="#FFDDDDDD" ResizeBehavior="PreviousAndNext"/>
203207

204-
<igDP:XamDataPresenter x:Name="dataPresenter1" Grid.Column="2" Theme="Office2013" Margin="5,0,0,0">
208+
<igDP:XamDataPresenter x:Name="dataPresenter1" Grid.Column="2" Theme="{Binding ElementName=cboThemes, Path=SelectedValue, Mode=OneWay}" Margin="5,0,0,0">
205209
<igDP:XamDataPresenter.FieldLayoutSettings>
206210
<igDP:FieldLayoutSettings FilterEvaluationMode="UseCollectionView"/>
207211
</igDP:XamDataPresenter.FieldLayoutSettings>

DataPresenter.DataSources.OData/DataPresenter.DataSources.OData.SampleApp/MainWindow.xaml.cs

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public MainWindow()
4444
this.cboDataPresenterView.SelectedIndex = 0;
4545
this.cboRecordFilterLogicalOperator.SelectedIndex = 0;
4646

47-
// Initialize the color picker with the current DataPendingOverlayBrush.
48-
if (this.dataPresenter1.Resources.Contains(DataPresenterBrushKeys.DataPendingOverlayBrushKey))
49-
{
50-
SolidColorBrush overlayBrush = this.dataPresenter1.Resources[DataPresenterBrushKeys.DataPendingOverlayBrushKey] as SolidColorBrush;
51-
if (null != overlayBrush)
52-
this.colorPicker.SelectedColor = overlayBrush.Color;
53-
}
47+
// Listen to the XamDataPresenter's ThemeChanged event so we can initialize the DataPendingOverlayBrush color picker when the Theme changes.
48+
this.dataPresenter1.ThemeChanged += (s,e) => { this.Dispatcher.BeginInvoke(new Action(() => this.InitializeColorPicker()), System.Windows.Threading.DispatcherPriority.ApplicationIdle); };
49+
50+
// Initialize the list of themes and select 'Office2013'.
51+
this.cboThemes.ItemsSource = Infragistics.Windows.Themes.ThemeManager.GetThemes();
52+
this.cboThemes.SelectedValue = "Office2013";
53+
5454
}
5555
#endregion //Constructor
5656

@@ -137,6 +137,23 @@ private Infragistics.Windows.DataPresenter.TreeView TreeView
137137

138138
#endregion //Private Properties
139139

140+
#region Private Methods
141+
142+
#region InitializeColorPicker
143+
private void InitializeColorPicker()
144+
{
145+
// Initialize the color picker with the current DataPendingOverlayBrush.
146+
if (this.dataPresenter1.Resources.Contains(DataPresenterBrushKeys.DataPendingOverlayBrushKey))
147+
{
148+
SolidColorBrush overlayBrush = this.dataPresenter1.Resources[DataPresenterBrushKeys.DataPendingOverlayBrushKey] as SolidColorBrush;
149+
if (null != overlayBrush && overlayBrush.Color != this.colorPicker.SelectedColor)
150+
this.colorPicker.SelectedColor = overlayBrush.Color;
151+
}
152+
}
153+
#endregion //InitializeColorPicker
154+
155+
#endregion //Private Methods
156+
140157
#region Event Handlers
141158

142159
#region cboDataPresenterView_SelectionChanged
@@ -244,17 +261,35 @@ private void cboRecordFilterLogicalOperator_SelectionChanged(object sender, Sele
244261
}
245262
#endregion //cboRecordFilterLogicalOperator_SelectionChanged
246263

264+
#region cboThemes_SelectionChanged
265+
private void cboThemes_SelectionChanged(object sender, SelectionChangedEventArgs e)
266+
{
267+
// Remove the existing DataPendingOverlayBrush resource (if any) from the XamDataPresenter Resources dictionary.
268+
if (this.dataPresenter1.Resources.Contains(DataPresenterBrushKeys.DataPendingOverlayBrushKey))
269+
this.dataPresenter1.Resources.Remove(DataPresenterBrushKeys.DataPendingOverlayBrushKey);
270+
}
271+
#endregion //cboThemes_SelectionChanged
272+
247273
#region colorPicker_SelectedColorChanged
248274
private void colorPicker_SelectedColorChanged(object sender, Infragistics.Controls.Editors.SelectedColorChangedEventArgs e)
249275
{
250276
if (e.NewColor.HasValue)
251277
{
252-
// Remove the existing DataPendingOverlayBrush resource from the XamDataPresenter Resources dictionary.
278+
// Remove the existing DataPendingOverlayBrush resource (if any) from the XamDataPresenter Resources dictionary.
253279
if (this.dataPresenter1.Resources.Contains(DataPresenterBrushKeys.DataPendingOverlayBrushKey))
254-
this.dataPresenter1.Resources.Remove(DataPresenterBrushKeys.DataPendingOverlayBrushKey);
255-
256-
// Add a new DataPendingOverlayBrush resource for the selected color to the XamDataPresenter Resources dictionary.
257-
this.dataPresenter1.Resources.Add(DataPresenterBrushKeys.DataPendingOverlayBrushKey, new SolidColorBrush(e.NewColor.Value));
280+
{
281+
SolidColorBrush brush = this.dataPresenter1.Resources[DataPresenterBrushKeys.DataPendingOverlayBrushKey] as SolidColorBrush;
282+
if (brush.Color != e.NewColor.Value)
283+
{
284+
this.dataPresenter1.Resources.Remove(DataPresenterBrushKeys.DataPendingOverlayBrushKey);
285+
286+
// Add a new DataPendingOverlayBrush resource for the selected color to the XamDataPresenter Resources dictionary.
287+
this.dataPresenter1.Resources.Add(DataPresenterBrushKeys.DataPendingOverlayBrushKey, new SolidColorBrush(e.NewColor.Value));
288+
}
289+
}
290+
else
291+
// Add a new DataPendingOverlayBrush resource for the selected color to the XamDataPresenter Resources dictionary.
292+
this.dataPresenter1.Resources.Add(DataPresenterBrushKeys.DataPendingOverlayBrushKey, new SolidColorBrush(e.NewColor.Value));
258293
}
259294
}
260295
#endregion //colorPicker_SelectedColorChanged

0 commit comments

Comments
 (0)