NullReferenceExplantion(C#)

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
baby2478nishi
記事: 52
登録日時: 10年前
住所: 兵庫県姫路市

NullReferenceExplantion(C#)

#1

投稿記事 by baby2478nishi » 9年前

デバッグしボタンを押すと

NullReferenceExplantionはハンドルされませんでした。
型 'System.NullReferenceException' のハンドルされていない例外が PresentationFramework.dll で発生しました
追加情報:オブジェクト参照がオブジェクト インスタンスに設定されていません。

と表示されます。
コードは前書いたものの続きというか違うものです。

コード:

//Settings1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPF
{
    /// <summary>
    /// Settings1.xaml の相互作用ロジック
    /// </summary>
    public partial class Settings1 : Window
    {
        public Settings1()
        {
            InitializeComponent();
        }

        private void btn0_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void radio_TCP_Checked(object sender, RoutedEventArgs e)//ラジオボタンTCP
        {
            this.changebar.DataContext = "TCP";
        }

        private void radio_UDP_Checked(object sender, RoutedEventArgs e)//ラジオボタンUDP
        {
            this.changebar.DataContext = "UDP";
        }

/*        // ラジオボタンのチェック状態変更時の処理
        // チェックがオンになった場合の処理
        private void radio_TCP_Checked(object sender, RoutedEventArgs e)
        {
            this.changebar.DataContext = "チェックがオンになりました";
        }*/

    }
}

コード:

<Window x:Class="WPF.Settings1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF"
        mc:Ignorable="d"
        Title="Settings1" Height="400" Width="600">
    <Grid>
        <Button Name="btn0" HorizontalAlignment="Center" 
        			VerticalAlignment="Center" Width="60" Height="48" Margin="522,10,10,311" Click="btn0_Click">
            閉じる
        </Button>
        <TextBlock x:Name="JavaPlace" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Javaの場所" VerticalAlignment="Top" Width="100" Height="20"/>
        <TextBox x:Name="JavaPlace_Box" HorizontalAlignment="Left" Height="23" Margin="10,35,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="161"/>
        <TextBlock x:Name="PortSettings" HorizontalAlignment="Left" Margin="10,292,0,0" TextWrapping="Wrap" Text="ポート設定" VerticalAlignment="Top" Width="100" Height="20" RenderTransformOrigin="-0.29,0.6"/>
        <RadioButton x:Name="radio_TCP" Content="TCP" HorizontalAlignment="Left" Margin="10,312,0,0" VerticalAlignment="Top" Width="45" Height="15" GroupName="UPnP_Type" IsChecked="True" Checked="radio_TCP_Checked"/>
        <RadioButton x:Name="radio_UDP" Content="UDP" HorizontalAlignment="Left" Margin="10,332,0,0" VerticalAlignment="Top" Width="45" GroupName="UPnP_Port" Checked="radio_UDP_Checked"/>
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="60,318,0,0" TextWrapping="Wrap" Text="25565" VerticalAlignment="Top" Width="73"/>
        <TextBlock x:Name="changebar" HorizontalAlignment="Left" Margin="10,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="572"/>
    </Grid>
</Window>


baby2478nishi
記事: 52
登録日時: 10年前
住所: 兵庫県姫路市

Re: NullReferenceExplantion(C#)

#2

投稿記事 by baby2478nishi » 9年前

エラーが出るのは25行目です。

よろしくお願いします。

YuO
記事: 947
登録日時: 14年前
住所: 東京都世田谷区

Re: NullReferenceExplantion(C#)

#3

投稿記事 by YuO » 9年前

そもそも,例外デバッグアシスタントがさきに起動すると思うのですが。
そして,その選択肢には例外内容をコピーする,というものがあるはずです。それを選択すると,

コード:

System.Reflection.TargetInvocationException はハンドルされませんでした。
  HResult=-2146232828
  Message=呼び出しのターゲットが例外をスローしました。
  Source=mscorlib
  StackTrace:
       場所 System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       場所 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       場所 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       場所 System.Activator.CreateInstance(Type type, Boolean nonPublic)
       場所 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
       場所 System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       場所 System.Activator.CreateInstance(Type type, Object[] args)
       場所 System.Xaml.Schema.SafeReflectionInvoker.CreateInstanceCritical(Type type, Object[] arguments)
       場所 System.Xaml.Schema.SafeReflectionInvoker.CreateInstance(Type type, Object[] arguments)
       場所 System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
       場所 MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
       場所 MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
       場所 System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
       場所 System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
       場所 System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       場所 System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
       場所 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       場所 System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       場所 System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       場所 System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
       場所 System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
       場所 System.Windows.Application.DoStartup()
       場所 System.Windows.Application.<.ctor>b__1_0(Object unused)
       場所 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       場所 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       場所 System.Windows.Threading.DispatcherOperation.InvokeImpl()
       場所 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       場所 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
       場所 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       場所 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
       場所 System.Windows.Threading.DispatcherOperation.Invoke()
       場所 System.Windows.Threading.Dispatcher.ProcessQueue()
       場所 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       場所 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       場所 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       場所 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       場所 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       場所 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       場所 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       場所 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       場所 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       場所 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       場所 System.Windows.Application.RunDispatcher(Object ignore)
       場所 System.Windows.Application.RunInternal(Window window)
       場所 System.Windows.Application.Run(Window window)
       場所 System.Windows.Application.Run()
       場所 WPF.App.Main() 場所 D:\Program\Visual Studio\2015\WPF\WPF\obj\Debug\App.g.cs:行 0
       場所 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       場所 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       場所 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       場所 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       場所 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       場所 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2147467261
       Message=オブジェクト参照がオブジェクト インスタンスに設定されていません。
       Source=WPF
       StackTrace:
            場所 WPF.Settings1.radio_TCP_Checked(Object sender, RoutedEventArgs e) 場所 D:\Program\Visual Studio\2015\WPF\WPF\Settings1.xaml.cs:行 35
            場所 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
            場所 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
            場所 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
            場所 System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
            場所 System.Windows.Controls.RadioButton.OnChecked(RoutedEventArgs e)
            場所 System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            場所 System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
            場所 System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
            場所 System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
            場所 System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
            場所 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
            場所 System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
            場所 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
            場所 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
            場所 System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
            場所 System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
            場所 System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
            場所 System.Xaml.XamlObjectWriter.WriteEndMember()
            場所 System.Xaml.XamlWriter.WriteNode(XamlReader reader)
            場所 System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
            場所 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
            場所 System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
            場所 System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
            場所 System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
            場所 WPF.Settings1.InitializeComponent() 場所 D:\Program\Visual Studio\2015\WPF\WPF\Settings1.xaml:行 1
            場所 WPF.Settings1..ctor() 場所 D:\Program\Visual Studio\2015\WPF\WPF\Settings1.xaml.cs:行 25
       InnerException: 
のような出力がコピーされるはずです。

で,StackTraceを見ると,TargetInvocationExceptionのInnerExceptionであるNullReferenceExceptionが発生したのは25行目ではなく35行目です。

35行目にブレークポイントを置いて実行してみると,確かに初回の実行時,changebarはnullです。
おそらく,上から下にXAMLが実体化されていく過程で,changebarの実体化よりも先にradio_TCP_Checkedが呼ばれているのだと思います。

で,回避手段は,
  • if文で分岐する
  • radio_TCP_CheckedイベントハンドラをコンストラクタのInitializeComponentの後ろで設定するようにする
  • radio_TCP.IsCheckedプロパティの設定をコンストラクタのInitializeComponentの後ろで設定するようにする
  • changebarへの設定はEventTriggerで頑張る
  • ViewModelをWindowのDataContextに設定し,IsTcpCheckedのようなプロパティをradio_TCP.IsCheckedにbind,changebar.TextをChangebarTextのようなプロパティにbind,IsTcpCheckedのsetterでChangebarTextを変更してPropertyChangedイベントで変更通知
あたりでしょうか。
WPFらしい書き方は後ろ2つで,私は結構最後の物の変形で処理しています。
オフトピック
ChangebarTextのような,テキストを直接,というものは使わず,
  • intやEnumのプロパティにしてDataTriggerでTextを設定する
  • メッセージ分のTextBlockを用意しておき,VisibilityプロパティにBooleanToVisibilityConverterかましたBooleanなプロパティをbindする
等で対処。
----付録的に----
XAMLでEventTriggerを使って値を設定する例 (Blend使って設定したママ)。ついでに,Gridを使ってサイズ変更にも対応させてみた。

コード:

<Window x:Class="WPF.Settings1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF"
        mc:Ignorable="d"
        Title="Settings1" Height="400" Width="600">
    <Window.Resources>
        <Storyboard x:Key="OnChecked1">
            <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="changebar">
                <DiscreteStringKeyFrame KeyTime="0" Value="TCP"/>
            </StringAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnChecked2">
            <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="changebar">
                <DiscreteStringKeyFrame KeyTime="0" Value="UDP"/>
            </StringAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="radio_TCP">
            <BeginStoryboard Storyboard="{StaticResource OnChecked1}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="radio_UDP">
            <BeginStoryboard Storyboard="{StaticResource OnChecked2}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource OnChecked1}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="0" Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" x:Name="JavaPlace" HorizontalAlignment="Left" Margin="5" TextWrapping="Wrap" Text="Javaの場所" VerticalAlignment="Top" />
            <TextBox Grid.Row="1" Grid.Column="0" x:Name="JavaPlace_Box" HorizontalAlignment="Left" Height="23" Margin="5" TextWrapping="Wrap" VerticalAlignment="Top" Width="161"/>
        </Grid>
        <Button Grid.Row="0" Grid.Column="2" Name="btn0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60" Height="48" Margin="5" Click="btn0_Click">閉じる</Button>

        <Grid Grid.Row="2" Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="PortSettings" HorizontalAlignment="Left" Margin="5" TextWrapping="Wrap" Text="ポート設定" VerticalAlignment="Top" />
            <RadioButton Grid.Row="1" Grid.Column="0" x:Name="radio_TCP" Content="TCP" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="45" Height="15" GroupName="UPnP_Type" IsChecked="True" />
            <RadioButton Grid.Row="2" Grid.Column="0" x:Name="radio_UDP" Content="UDP" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="45" GroupName="UPnP_Type" />
            <TextBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="1" x:Name="textBox" Height="23" Margin="5" TextWrapping="Wrap" Text="25565" VerticalAlignment="Center" Width="73"/>
        </Grid>
        <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" x:Name="changebar" HorizontalAlignment="Left" Margin="5" TextWrapping="Wrap" VerticalAlignment="Center" TextAlignment="Left" />
    </Grid>
</Window>

baby2478nishi
記事: 52
登録日時: 10年前
住所: 兵庫県姫路市

Re: NullReferenceExplantion(C#)

#4

投稿記事 by baby2478nishi » 9年前

ありがとうございます!
YuOさんが付録として書かれていたコードを使わせていただきました。

あともう一点聞きたいのですが、現状だと拡大ボタンを押すと線が途切れてしまいます。その原因がウィンドウサイズ指定(というか長方形を描くものを簡易的に線として利用しているからというのはわかるのですが対処法がわかりません。どうすればよいですか?

YuO
記事: 947
登録日時: 14年前
住所: 東京都世田谷区

Re: NullReferenceExplantion(C#)

#5

投稿記事 by YuO » 9年前

baby2478nishi さんが書きました:あともう一点聞きたいのですが、現状だと拡大ボタンを押すと線が途切れてしまいます。その原因がウィンドウサイズ指定(というか長方形を描くものを簡易的に線として利用しているからというのはわかるのですが対処法がわかりません。どうすればよいですか?
線が途切れるとはどういうことでしょうか。
Rectangleクラス等のSystem.Windows.Shapes名前空間内のクラスはFrameworkElementであるため、Gridの子要素になります。
Lineクラス等をコードから追加する場合でも、Grid.RowGrid.Column添付プロパティを設定することで、Gridのセルに合わせてサイズが変更されるようになります。

最初のうちは、
  • 基本的にGridベースでレイアウトを設計する
  • Gridの1つのセルには1つのコントロールしか含めない
  • RowDefinition/ColumnDefinitionでのHeight/Widthは、できるだけ自動設定 (auto) や相対指定 (*, 2*等) を使い、ピクセル数の指定は避ける
  • コントロールのWidth/Height指定は可能な限り避ける
  • コントロールのMarginは、セル内に留まるように指定する (負数の指定等は避ける)
  • 動的なコントロールの追加は可能な限り避ける
あたりを気にして作るとよいかと。
ネットを検索すると、パフォーマンス関連でGridのレイアウトは重いとか、WidthやHeightはハードコードしろ、といった話が出てきたりしますが、それは基本となるGridベースでのレイアウトが出来てからの話だと思います。

baby2478nishi
記事: 52
登録日時: 10年前
住所: 兵庫県姫路市

Re: NullReferenceExplantion(C#)

#6

投稿記事 by baby2478nishi » 9年前

線が切れるというのは添付の画像のような状態です。
RowDefinition/ColumnDefinitionでのHeight/Widthは、できるだけ自動設定 (auto) や相対指定 (*, 2*等) を使い、ピクセル数の指定は避ける
という方法で頑張ってみたいと思います

閉鎖

“C言語何でも質問掲示板” へ戻る