Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- ServiceHostingEnvironment.cs
- HtmlElementEventArgs.cs
- parserscommon.cs
- BinaryCommonClasses.cs
- GenericParameterDataContract.cs
- Model3D.cs
- StringDictionary.cs
- TableLayoutCellPaintEventArgs.cs
- ConfigurationPropertyCollection.cs
- GradientBrush.cs
- WmpBitmapDecoder.cs
- TableCellCollection.cs
- MultiBinding.cs
- ContextMenuStrip.cs
- TemplateControlCodeDomTreeGenerator.cs
- DesignerWidgets.cs
- QuaternionAnimationUsingKeyFrames.cs
- StylusButton.cs
- SessionState.cs
- TitleStyle.cs
- CompilerGlobalScopeAttribute.cs
- PrinterSettings.cs
- followingsibling.cs
- QilLiteral.cs
- SystemWebSectionGroup.cs
- SmtpFailedRecipientsException.cs
- OracleParameter.cs
- RuntimeVariableList.cs
- SchemaNames.cs
- ChildrenQuery.cs
- GridViewColumnHeaderAutomationPeer.cs
- ModuleElement.cs
- DesignerSelectionListAdapter.cs
- ViewDesigner.cs
- NameValueFileSectionHandler.cs
- SimpleMailWebEventProvider.cs
- Page.cs
- ContentValidator.cs
- EncoderExceptionFallback.cs
- UIElement3DAutomationPeer.cs
- EllipseGeometry.cs
- ThreadPoolTaskScheduler.cs
- MultiByteCodec.cs
- xdrvalidator.cs
- HealthMonitoringSectionHelper.cs
- IsolatedStorageFilePermission.cs
- DiscoveryReference.cs
- PreservationFileWriter.cs
- ListBoxItemWrapperAutomationPeer.cs
- XmlCharCheckingReader.cs
- CharAnimationBase.cs
- TextDecorationCollection.cs
- shaper.cs
- counter.cs
- MethodImplAttribute.cs
- NamespaceEmitter.cs
- SafeReversePInvokeHandle.cs
- BamlLocalizabilityResolver.cs
- DbParameterCollectionHelper.cs
- Accessible.cs
- TemplatePartAttribute.cs
- basecomparevalidator.cs
- UnsafeNativeMethodsTablet.cs
- KoreanLunisolarCalendar.cs
- MembershipUser.cs
- DynamicArgumentDesigner.xaml.cs
- WorkflowPageSetupDialog.cs
- DBConnectionString.cs
- GridViewRowPresenter.cs
- LoginView.cs
- CommonRemoteMemoryBlock.cs
- FormsAuthentication.cs
- SqlConnectionPoolGroupProviderInfo.cs
- Translator.cs
- FontStyleConverter.cs
- SourceFileBuildProvider.cs
- Matrix3DStack.cs
- Int32Rect.cs
- SinglePhaseEnlistment.cs
- SHA512.cs
- DataListCommandEventArgs.cs
- PermissionSetTriple.cs
- APCustomTypeDescriptor.cs
- Journal.cs
- UnicastIPAddressInformationCollection.cs
- CatalogPartChrome.cs
- OleDbCommandBuilder.cs
- OperationResponse.cs
- Timer.cs
- StrongNameUtility.cs
- Sentence.cs
- RawStylusInputCustomDataList.cs
- EpmCustomContentDeSerializer.cs
- CodeExporter.cs
- StaticFileHandler.cs
- SubtreeProcessor.cs
- EventProvider.cs
- WhiteSpaceTrimStringConverter.cs
- WebPartsSection.cs
- ListViewSortEventArgs.cs