0

我开始在 WindowsPhone 中开发应用程序,但遇到了一些问题。我试图动态添加画布,但它不起作用,我可能忘记了一些事情,你能帮忙发现我的错误吗?下面的代码来自我的学习应用程序,它是基本的 Win Phone 应用程序。

cs代码:

public MainPage()
    {
        InitializeComponent();

        int size = 50;
        Canvas myCanvas = new Canvas();
        Canvas.SetLeft(myCanvas, 0);
        myCanvas.Width = size;

        Color c = new Color();
        c.R = 255;
        c.B = 0;
        c.G = 255;

        myCanvas.Background = new SolidColorBrush(c);

        ContentPanel.Height = 100;
        ContentPanel.Width = 100;
        ContentPanel.Children.Add(myCanvas);
        ApplicationTitle.Text = ContentPanel.ActualHeight.ToString();

    }

xml

    <Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

    </Grid>
</Grid>
4

1 回答 1

1

我不太确定你想用 Canvas 在这里完成什么。您可能需要查看其他控件以获取您想要执行的操作。

话虽如此,问题在于您缺少颜色中的“Alpha”组件。这使它变得透明。

改变:

    Color c = new Color();
    c.R = 255;
    c.B = 0;
    c.G = 255;

    c.A = 255;  // this is what you need to add to make it visible.
于 2012-04-21T13:43:02.900 回答