Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- TypeSystem.cs
- MinimizableAttributeTypeConverter.cs
- basemetadatamappingvisitor.cs
- CodeSnippetStatement.cs
- PageBuildProvider.cs
- SecurityAttributeGenerationHelper.cs
- BamlResourceSerializer.cs
- UrlPath.cs
- CoreSwitches.cs
- WindowVisualStateTracker.cs
- PinnedBufferMemoryStream.cs
- RegexMatch.cs
- BoundColumn.cs
- WindowsEditBox.cs
- MessageQueueCriteria.cs
- TabletCollection.cs
- MetadataCache.cs
- AddInDeploymentState.cs
- SystemThemeKey.cs
- SystemTcpConnection.cs
- DbDataSourceEnumerator.cs
- _MultipleConnectAsync.cs
- BinarySerializer.cs
- RNGCryptoServiceProvider.cs
- PositiveTimeSpanValidator.cs
- Pair.cs
- BaseServiceProvider.cs
- EventWaitHandle.cs
- SemanticAnalyzer.cs
- Compiler.cs
- LinqDataSource.cs
- ContextMenuStrip.cs
- InfoCardAsymmetricCrypto.cs
- SiteIdentityPermission.cs
- TrimSurroundingWhitespaceAttribute.cs
- CacheOutputQuery.cs
- BitmapFrameEncode.cs
- InternalBufferOverflowException.cs
- EdmConstants.cs
- UnsafeNativeMethods.cs
- ExceptionCollection.cs
- AspNetCompatibilityRequirementsMode.cs
- CommandHelper.cs
- CollectionBuilder.cs
- DCSafeHandle.cs
- XmlReader.cs
- GestureRecognizer.cs
- ProcessHostMapPath.cs
- KeyValuePairs.cs
- StretchValidation.cs
- Point3DConverter.cs
- SqlSelectClauseBuilder.cs
- ISAPIWorkerRequest.cs
- MaterialGroup.cs
- HandlerFactoryCache.cs
- NamespaceCollection.cs
- WindowsUpDown.cs
- CertificateManager.cs
- EmbeddedMailObjectsCollection.cs
- Compiler.cs
- TreeNodeMouseHoverEvent.cs
- LinkConverter.cs
- coordinatorscratchpad.cs
- EntitySetBase.cs
- DataObjectMethodAttribute.cs
- ArglessEventHandlerProxy.cs
- RequestCacheEntry.cs
- OperationCanceledException.cs
- MethodBuilderInstantiation.cs
- FormClosedEvent.cs
- PerformanceCounterPermission.cs
- DataGridViewDataConnection.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- VectorCollectionConverter.cs
- MulticastDelegate.cs
- ApplicationTrust.cs
- KoreanCalendar.cs
- XDeferredAxisSource.cs
- BasicExpressionVisitor.cs
- TextServicesCompartmentContext.cs
- PtsHost.cs
- XPathMessageFilterTable.cs
- Main.cs
- CompilerErrorCollection.cs
- AppSecurityManager.cs
- HtmlSelectionListAdapter.cs
- UpdatePanelTriggerCollection.cs
- TableProviderWrapper.cs
- File.cs
- parserscommon.cs
- DragEventArgs.cs
- ResourceProviderFactory.cs
- EnlistmentTraceIdentifier.cs
- Identifier.cs
- AnonymousIdentificationModule.cs
- SoapIgnoreAttribute.cs
- SafeNativeMethodsOther.cs
- TableLayoutColumnStyleCollection.cs
- UIElementParaClient.cs
- RegexMatchCollection.cs