単純な WP8 を作成していますが、コントロールの非表示 ( Visibilityプロパティの変更) に問題があります。
XAML に追加しましたxmlns:local="clr-namespace:MyProjectName"
( も試しましたusing
)。XAML は次のように構成されます。
<phone:PhoneApplicationPage
x:Class="MyProjectName.Pages.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyProjectName"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True" Margin="0,4,0,-4" Background="#FFBD3F3F">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}" >
<Grid x:Name="ContentPanel" Grid.Row="1" >
<Grid.Resources>
<local:VisibilityFormatter x:Key="FormatConverter" />
</Grid.Resources>
<phone:LongListSelector Grid.Row="4">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Obj}"
Visibility="{Binding ObjVisibility,
Mode=OneWay,
Converter={StaticResource FormatConverter}}" />
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</Grid>
問題は次の<local:...>
行にあります。The name "VisibilityFormatter" does not exist in the namespace "clr-namespace:MyProjectName".
クラスは次のように定義されます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace MyProjectName
{
public class Formatter
{
public class VisibilityFormatter : IValueConverter
{
// Retrieve the format string and use it to format the value.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var visibility = parameter as bool?;
return visibility.HasValue && visibility.Value ? Visibility.Visible : Visibility.Collapsed;
}
// No need to implement converting back on a one-way binding
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}
このクラスObjInfo
は、次の 2 つのプロパティを持つ単純なパブリック クラスです。
namespace MyProjectName.Models
{
public class ObjInfo
{
public bool ObjVisibility { get; set; }
public string Obj { get; set; }
}
}
この質問に似ていますが、移行は含まれていません。私は最初からWP8で開発しています。
私は何を達成しようとしていますか?良い。そのプロパティにコントロールを表示するかどうかを格納していbool
ます。XAML コントロールのプロパティは のみを認識し、 を認識しVisibility
enum
ないbool
ため、それをその に変換する必要がありenum
ます。