【问题标题】:How to write XAML + C# code to be compiled only in Debug Mode? [duplicate]如何编写仅在调试模式下编译的 XAML + C# 代码? [复制]
【发布时间】:2014-09-04 14:36:49
【问题描述】:

我有一些严重的问题,这不是错误,而是代码质量问题。目前我正在使用一个 VS2013 解决方案来涵盖我的程序的调试和发布版本。据我所知,使用这个:

[Conditional("DEBUG")]

在一个方法解决了代码隐藏中过多的 C# 代码的问题之前,但是过多的 XAML 呢?我想摆脱 XAML 中的这段代码:

<HubSection x:Name="debug" Header="debug">
    <DataTemplate>
        <Grid>
            <StackPanel HorizontalAlignment="Center">
                <Button x:Name="testowy_button" Content="Test: plik lokalny." Click="TestOne" />
                <Button x:Name="testowy_button_2" Content="Test: biblioteka." Click="TestTwo" />
                <Button Content="Test: z wewnątrz wątku tła." Click="TestBackground" />
                <Button Content="Zrzut playlisty do Debugu." Click="CommandToDump" />
            </StackPanel>
        </Grid>
    </DataTemplate>
</HubSection>

摆脱我并不是说将其设置为 Visibility.Hidden,这很容易。如何在 Release 中从编译中排除某些 XAML?有什么想法吗?

最好的问候。 :)

【问题讨论】:

    标签: c# wpf xaml windows-phone-8.1


    【解决方案1】:

    对于 C# 代码,您可以使用 #if DEBUG preprocessor directive

    对于 XAML:possible duplicate

    【讨论】:

    • 对于设置 C# 代码的任何部分,#IF DEBUG 当然可以完美运行。但是考虑到 XAML,不幸的是,添加命名空间仅适用于样式等。还是没有解决。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多