Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Controls / BooleanToVisibilityConverter.cs / 1 / BooleanToVisibilityConverter.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Data;
using System.Globalization;
using System.Collections.Generic;
using MS.Internal.Controls;
namespace System.Windows.Controls
{
///
/// Convert between boolean and visibility
///
[Localizability(LocalizationCategory.NeverLocalize)]
public sealed class BooleanToVisibilityConverter : IValueConverter
{
///
/// Convert bool or Nullable<bool> to Visibility
///
/// bool or Nullable<bool>
/// Visibility
/// null
/// null
/// Visible or Collapsed
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool bValue = false;
if (value is bool)
{
bValue = (bool)value;
}
else if (value is Nullable)
{
Nullable tmp = (Nullable)value;
bValue = tmp.HasValue ? tmp.Value : false;
}
return (bValue) ? Visibility.Visible : Visibility.Collapsed;
}
///
/// Convert Visibility to boolean
///
///
///
///
///
///
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility)
{
return (Visibility)value == Visibility.Visible;
}
else
{
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Data;
using System.Globalization;
using System.Collections.Generic;
using MS.Internal.Controls;
namespace System.Windows.Controls
{
///
/// Convert between boolean and visibility
///
[Localizability(LocalizationCategory.NeverLocalize)]
public sealed class BooleanToVisibilityConverter : IValueConverter
{
///
/// Convert bool or Nullable<bool> to Visibility
///
/// bool or Nullable<bool>
/// Visibility
/// null
/// null
/// Visible or Collapsed
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool bValue = false;
if (value is bool)
{
bValue = (bool)value;
}
else if (value is Nullable)
{
Nullable tmp = (Nullable)value;
bValue = tmp.HasValue ? tmp.Value : false;
}
return (bValue) ? Visibility.Visible : Visibility.Collapsed;
}
///
/// Convert Visibility to boolean
///
///
///
///
///
///
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility)
{
return (Visibility)value == Visibility.Visible;
}
else
{
return false;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StrongNameSignatureInformation.cs
- PropertyCollection.cs
- CodeMemberEvent.cs
- RoutedEventValueSerializer.cs
- PolicyException.cs
- RegisteredArrayDeclaration.cs
- EncryptedPackageFilter.cs
- SqlConnectionPoolProviderInfo.cs
- ToolStripCustomTypeDescriptor.cs
- TransportContext.cs
- FixedDSBuilder.cs
- ListViewSelectEventArgs.cs
- BinaryObjectInfo.cs
- PageWrapper.cs
- LogSwitch.cs
- uribuilder.cs
- HealthMonitoringSection.cs
- SqlNamer.cs
- PropertyValidationContext.cs
- XpsS0ValidatingLoader.cs
- AutomationTextAttribute.cs
- DataGridViewImageCell.cs
- SystemException.cs
- ThicknessAnimation.cs
- UrlAuthFailedErrorFormatter.cs
- RefType.cs
- ScriptReferenceBase.cs
- TextTreeInsertUndoUnit.cs
- DataServiceQueryOfT.cs
- TableAdapterManagerGenerator.cs
- DataGridViewColumnStateChangedEventArgs.cs
- TextEmbeddedObject.cs
- LogReservationCollection.cs
- FocusManager.cs
- ControlValuePropertyAttribute.cs
- QueryOperator.cs
- ScrollViewerAutomationPeer.cs
- SharedPerformanceCounter.cs
- LicenseException.cs
- MergeFailedEvent.cs
- HGlobalSafeHandle.cs
- DbProviderFactory.cs
- XamlInt32CollectionSerializer.cs
- DateTimeSerializationSection.cs
- ContextStaticAttribute.cs
- DataGridTablesFactory.cs
- ServicePointManager.cs
- GcHandle.cs
- HttpCookieCollection.cs
- EdmItemCollection.cs
- OpCellTreeNode.cs
- FilterElement.cs
- DataGridViewCellStyleChangedEventArgs.cs
- Transactions.cs
- FieldAccessException.cs
- VisualTreeHelper.cs
- CompositeDuplexBindingElement.cs
- AsymmetricKeyExchangeFormatter.cs
- DragEvent.cs
- IfAction.cs
- SiteMapNodeItem.cs
- CompilerScope.cs
- Classification.cs
- ServiceOperation.cs
- WebResourceUtil.cs
- _RequestCacheProtocol.cs
- AbsoluteQuery.cs
- Storyboard.cs
- DataTableClearEvent.cs
- TableCellAutomationPeer.cs
- Polygon.cs
- FontStyle.cs
- XsltArgumentList.cs
- FragmentQueryProcessor.cs
- RangeBase.cs
- TextRangeSerialization.cs
- ReflectionHelper.cs
- Misc.cs
- GeometryDrawing.cs
- NetPipeSectionData.cs
- StrictAndMessageFilter.cs
- SHA512CryptoServiceProvider.cs
- ObjectListItem.cs
- CaseStatement.cs
- ExceptionHelpers.cs
- ModifierKeysConverter.cs
- RuleConditionDialog.Designer.cs
- RemotingAttributes.cs
- ProcessModuleDesigner.cs
- WindowsRichEdit.cs
- ImageInfo.cs
- FixedSOMLineRanges.cs
- TraceFilter.cs
- ReadOnlyHierarchicalDataSourceView.cs
- NativeActivityTransactionContext.cs
- SqlDataSourceCache.cs
- ProgressBarAutomationPeer.cs
- BufferModesCollection.cs
- ZipFileInfo.cs
- ToolTip.cs