Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / BooleanToVisibilityConverter.cs / 1305600 / 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
- UserNamePasswordClientCredential.cs
- TemplateComponentConnector.cs
- CustomAttributeBuilder.cs
- RijndaelManagedTransform.cs
- OutOfProcStateClientManager.cs
- StateInitializationDesigner.cs
- Color.cs
- UInt64Storage.cs
- WindowsComboBox.cs
- LambdaReference.cs
- DeploymentSection.cs
- CipherData.cs
- ColorTranslator.cs
- ReadOnlyMetadataCollection.cs
- ProfileModule.cs
- CompositeControl.cs
- odbcmetadatacollectionnames.cs
- SecureUICommand.cs
- EventLogLink.cs
- ApplicationFileParser.cs
- WeakReference.cs
- Scanner.cs
- UnknownBitmapEncoder.cs
- PropertyNames.cs
- ThicknessAnimationBase.cs
- ScrollEvent.cs
- ObjectStorage.cs
- BitmapSizeOptions.cs
- IList.cs
- Compiler.cs
- WebSysDisplayNameAttribute.cs
- RightsManagementEncryptionTransform.cs
- ServiceModelStringsVersion1.cs
- ClientOptions.cs
- SecurityTokenAuthenticator.cs
- WpfXamlType.cs
- TabPanel.cs
- objectquery_tresulttype.cs
- Asn1IntegerConverter.cs
- AutoGeneratedField.cs
- DataQuery.cs
- PopupControlService.cs
- EdmProperty.cs
- IntegerValidatorAttribute.cs
- WebConfigurationHostFileChange.cs
- ActivityMarkupSerializer.cs
- HttpServerProtocol.cs
- ElementUtil.cs
- Triangle.cs
- TimeoutException.cs
- CacheAxisQuery.cs
- DataGridViewColumnTypePicker.cs
- SmiMetaDataProperty.cs
- XmlBindingWorker.cs
- FontStyleConverter.cs
- XPathNavigator.cs
- MissingFieldException.cs
- _TimerThread.cs
- SiteMapHierarchicalDataSourceView.cs
- HtmlCalendarAdapter.cs
- EntityCommandDefinition.cs
- BaseAsyncResult.cs
- BackEase.cs
- StubHelpers.cs
- Substitution.cs
- IOException.cs
- DefaultAsyncDataDispatcher.cs
- TextElementCollectionHelper.cs
- FunctionUpdateCommand.cs
- ConstructorBuilder.cs
- BrowserCapabilitiesCodeGenerator.cs
- CompilerInfo.cs
- PreviewKeyDownEventArgs.cs
- NativeMethods.cs
- ItemsChangedEventArgs.cs
- BoundingRectTracker.cs
- FontStretches.cs
- ObjectView.cs
- VisualTarget.cs
- ListQueryResults.cs
- QilValidationVisitor.cs
- DateBoldEvent.cs
- Char.cs
- BitmapMetadataBlob.cs
- TemplateField.cs
- HtmlInputPassword.cs
- LocatorBase.cs
- SizeConverter.cs
- FontStretchConverter.cs
- ServiceEndpointCollection.cs
- PassportAuthentication.cs
- XsdDataContractImporter.cs
- EntityDataSourceDataSelection.cs
- Regex.cs
- FontDifferentiator.cs
- CollectionChangedEventManager.cs
- MessageSecurityOverHttpElement.cs
- ProfileModule.cs
- StringSorter.cs
- OpCellTreeNode.cs